package model

import "strings"

const (
	ImgTypeLocal = 0 // 京西自己用的，不需要上传至平台
	ImgTypeMain  = 1 // 商品主图
	ImgTypeDesc  = 2 // 商品描述详情

	MimeTypeJpeg = "image/jpeg"
	MimeTypePng  = "image/png"
	MimeTypeGif  = "image/gif"
)

var (
	ValidMimeTypes = map[string]int{
		MimeTypeJpeg: 1,
		MimeTypePng:  1,
		MimeTypeGif:  1,
	}
)

type DataResource struct {
	ModelIDCUL

	HashCode string `orm:"size(48);unique" json:"hashCode"`

	ResourceType string `orm:"size(48)" json:"resourceType"` // 资料的mime type
	Name         string `orm:"size(48);index" json:"name"`
	UseType      int8   `json:"useType"` // 图资源使用方式（大于0才可能需要上传至平台）

	MainURL  string `orm:"size(512);column(main_url);unique" json:"mainURL"`
	QiniuURL string `orm:"size(512);column(qiniu_url);index" json:"qiniuURL"`
	EbaiURL  string `orm:"size(512);column(ebai_url);index" json:"ebaiURL"`
	MtwmURL  string `orm:"size(512);column(mtwm_url);index" json:"mtwmURL"`
	JdsURL   string `orm:"size(512);column(jds_url);index" json:"jdsURL"`

	Remark string `orm:"size(1024)" json:"remark"`
}

func GetValidMimeTypeDesc() (desc string) {
	strList := []string{}
	for k := range ValidMimeTypes {
		strList = append(strList, k)
	}
	return strings.Join(strList, ",")
}
