package model

import "time"

const (
	StoreSkuBindStatusNA       = -2
	StoreSkuBindStatusDeleted  = -1
	StoreSkuBindStatusDontSale = 0
	StoreSkuBindStatusNormal   = 1
)

const (
	MaxStoreSkuStockQty = 9999
)

const (
	RequestTypeChangePrice  = 1
	RequestTypeFocusSkuName = 2
)

const (
	WeightCosntMenuG  = "1" // "g"
	WeightCosntMenuKG = "2" // "kg"
	WeightCosntMenuL  = "4" // "l"
	WeightCosntMenuML = "3" // "ml"

	WeightCosntStringG  = "g"
	WeightCosntStringKG = "kg"
	WeightCosntStringL  = "l"
	WeightCosntStringML = "ml"
)

const (
	RequestStatusNew      = 0
	RequestStatusRejected = -1
	RequestStatusAccepted = 1
	RequestStatusCanceled = 3
)

var (
	RequestTypeName = map[int]string{
		RequestTypeChangePrice:  "更改价格",
		RequestTypeFocusSkuName: "关注商品",
	}
	RequestStatusName = map[int]string{
		RequestStatusNew:      "待审核",
		RequestStatusRejected: "拒绝",
		RequestStatusAccepted: "已批准",
	}
)

type StoreSkuCategoryMap struct {
	ModelIDCULD

	StoreID    int `orm:"column(store_id)"`
	CategoryID int `orm:"column(category_id)"`

	EbaiID int64  `orm:"column(ebai_id);index"`
	MtwmID string `orm:"column(mtwm_id);index;size(16)"`
	TaoID  string `orm:"column(tao_id);index;size(16)"`
	DdID   string `orm:"column(dd_id);index;size(16)"`
	YbID   int64  `orm:"column(yb_id);index"`
	JdsID  int64  `orm:"column(jds_id);index"`

	EbaiSyncStatus int8 `orm:"default(2)"`
	MtwmSyncStatus int8 `orm:"default(2)"`
	TaoSyncStatus  int8 `orm:"default(2)"`
	DdSyncStatus   int8 `orm:"default(2)"`
	YbSyncStatus   int8 `orm:"default(2)"`
	JdsSyncStatus  int8 `orm:"default(2)"`
}

func (*StoreSkuCategoryMap) TableUnique() [][]string {
	return [][]string{
		[]string{"StoreID", "CategoryID", "DeletedAt"},
	}
}

func (*StoreSkuCategoryMap) TableIndex() [][]string {
	return [][]string{
		[]string{"CategoryID", "StoreID", "DeletedAt"},
	}
}

// type StoreSkuCategoryMap2 struct {
// 	ModelIDCULD

// 	StoreID    int `orm:"column(store_id)"`
// 	VendorID   int `orm:"column(vendor_id)"`
// 	CategoryID int `orm:"column(category_id)"`

// 	VendorCatID string `orm:"column(vendor_cat_id);size(48)" json:"vendorCatID"`
// 	SyncStatus  int8   `orm:"default(2)"`
// }

// func (*StoreSkuCategoryMap2) TableUnique() [][]string {
// 	return [][]string{
// 		[]string{"StoreID", "VendorID", "CategoryID", "DeletedAt"},
// 	}
// }

type StoreSkuBind struct {
	ModelIDCULD

	StoreID    int `orm:"column(store_id)"`
	SkuID      int `orm:"column(sku_id)"`
	SubStoreID int `orm:"column(sub_store_id)"`
	Price      int // 单位为分，不用int64的原因是这里不需要累加
	UnitPrice  int // 这个是一斤的门店商品价，放在这里的原因是避免额外增加一张store sku_name表，逻辑上要保证同一SKU NAME中的所有SKU这个字段的数据一致
	Stock      int `json:"stock"` //门店商品库存
	Status     int

	MtwmID           int64      `orm:"column(mtwm_id);index"`
	TaoID            int64      `orm:"column(tao_id);index"`
	EbaiID           int64      `orm:"column(ebai_id);index"`
	YbID             int64      `orm:"column(yb_id);index"`
	JdsID            int64      `orm:"column(jds_id);index"`
	JdsWareID        int64      `orm:"column(jds_ware_id)"`
	DdID             int64      `orm:"column(dd_id);index"`        // 子品主商品id
	VendorSonSkuID   string     `orm:"column(vendor_son_sku_id)"`  // 子商品skuid
	VendorSkuAttrId  string     `orm:"column(vendor_sku_attr_id)"` // 抖音需要,主品skuid
	VendorMainId     string     `orm:"column(vendor_Main_id)"`     // 抖音需要,商品主id
	JdSyncStatus     int8       `orm:"default(2)"`
	MtwmSyncStatus   int8       `orm:"default(2)"`
	TaoSyncStatus    int8       `orm:"default(2)"`
	DdSyncStatus     int8       `orm:"default(2)"`
	EbaiSyncStatus   int8       `orm:"default(2)"`
	YbSyncStatus     int8       `orm:"default(2)"`
	JdsSyncStatus    int8       `orm:"default(2)"` //京东商城
	JdPrice          int        `json:"jdPrice"`
	MtwmPrice        int        `json:"mtwmPrice"`
	TaoPrice         int        `json:"taoPrice"`
	EbaiPrice        int        `json:"ebaiPrice"`
	JxPrice          int        `json:"jxPrice"`
	DdPrice          int        `json:"ddPrice"`
	YbPrice          int        `json:"ybPrice"`
	JdsPrice         int        `json:"jdsPrice"`
	JdLockTime       *time.Time `orm:"null" json:"jdLockTime"`
	JdsLockTime      *time.Time `orm:"null" json:"jdsLockTime"`
	MtwmLockTime     *time.Time `orm:"null" json:"mtwmLockTime"`
	TaoLockTime      *time.Time `orm:"null" json:"taoLockTime"`
	EbaiLockTime     *time.Time `orm:"null" json:"ebaiLockTime"`
	JxLockTime       *time.Time `orm:"null" json:"jxLockTime"`
	YbLockTime       *time.Time `orm:"null" json:"ybLockTime"`
	DdLockTime       *time.Time `orm:"null" json:"ddLockTime"`
	AutoSaleAt       time.Time  `orm:"type(datetime);null" json:"autoSaleAt"`
	StatusSaleBegin  int16      //商品可售时间范围
	StatusSaleEnd    int16
	MtLadderBoxPrice int    `json:"mtLadderBoxPrice"` //美团门店商品包装费
	LocationCode     string `orm:"column(location_code)" json:"locationCode"`
}

func (*StoreSkuBind) TableUnique() [][]string {
	return [][]string{
		[]string{"StoreID", "SkuID", "DeletedAt"},
	}
}

func (*StoreSkuBind) TableIndex() [][]string {
	return [][]string{
		[]string{"SkuID", "StoreID", "DeletedAt"},
		// []string{"AutoSaleAt", "DeletedAt", "StoreID"},
	}
}

type StoreSkuBindHistory struct {
	StoreSkuBind
	StoreSkuBindID int       `orm:"column(store_sku_bind_id)"`
	SnapshotAt     time.Time `orm:"type(datetime);null;index" json:"snapshotAt"`
}

func (*StoreSkuBindHistory) TableUnique() [][]string {
	return [][]string{
		[]string{"StoreID", "SkuID", "DeletedAt", "SnapshotAt"},
	}
}

func (*StoreSkuBindHistory) TableIndex() [][]string {
	return [][]string{
		[]string{"SkuID", "StoreID", "DeletedAt"},
	}
}

type StoreOpRequest struct {
	ModelIDCULD // DeletedAt用于表示请求操作结束，而并不一定是删除

	Type      int8   `json:"type"`
	StoreID   int    `orm:"column(store_id)" json:"storeID"`
	ItemID    int    `orm:"column(item_id)" json:"itemID"` // 这个根据type不同，可能是SKUNAME ID或SKU ID
	Status    int8   `json:"status"`
	UserID    string `orm:"size(48);column(user_id)" json:"userID"`
	IntParam0 int    `json:"intParam0"` // 表示原价
	IntParam1 int    `json:"intParam1"`
	IntParam2 int    `json:"intParam2"`
	JsonParam string `orm:"size(3000)" json:"jsonParam"`
	Remark    string `orm:"size(255)" json:"remark"`
}

func (*StoreOpRequest) TableUnique() [][]string {
	return [][]string{
		[]string{"StoreID", "Type", "ItemID", "DeletedAt"},
	}
}

func (*StoreOpRequest) TableIndex() [][]string {
	return [][]string{
		[]string{"DeletedAt"},
		[]string{"StoreID", "Status", "Type"},
	}
}

type StoreSkuAudit struct {
	ModelIDCULD // DeletedAt用于表示请求操作结束，而并不一定是删除

	Type            int8   `json:"type"` //1为改价
	StoreID         int    `orm:"column(store_id)" json:"storeID"`
	NameID          int    `orm:"column(name_id)" json:"nameID"` // 这个根据type不同，可能是SKUNAME ID或SKU ID
	Status          int8   `json:"status"`                       //
	UserID          string `orm:"size(48);column(user_id)" json:"userID"`
	OriginUnitPrice int    `json:"originPrice"` // 表示原价
	UnitPrice       int    `json:"unitPrice"`   //老板申请的审核价格
	AuditPrice      int    `json:"auditPrice"`  //运营录入的审核价格
	Remark          string `orm:"size(255)" json:"remark"`
}

func (*StoreSkuAudit) TableIndex() [][]string {
	return [][]string{
		[]string{"StoreID", "Type", "NameID", "Status", "DeletedAt"},
	}
}
