package model

import (
	"time"
)

const (
	FieldID           = "ID"
	FieldParentID     = "ParentID"
	FieldDeletedAt    = "DeletedAt"
	FieldCreatedAt    = "CreatedAt"
	FieldUpdatedAt    = "UpdatedAt"
	FieldLastOperator = "LastOperator"
	FieldStatus       = "Status"
	FieldSyncStatus   = "SyncStatus"
	FieldJdSyncStatus = "JdSyncStatus"
	// FieldElmSyncStatus  = "ElmSyncStatus"
	FieldEbaiSyncStatus = "EbaiSyncStatus"
	FieldMtwmSyncStatus = "MtwmSyncStatus"
	FieldTaoSyncStatus  = "TaoSyncStatus"
	FieldDdSyncStatus   = "DdSyncStatus"
	// FieldWscSyncStatus  = "WscSyncStatus"
	FieldYbSyncStatus  = "YbSyncStatus"
	FieldJdsSyncStatus = "JdsSyncStatus"

	FieldVendorID      = "VendorID"
	FieldStoreID       = "StoreID"
	FieldVendorStoreID = "VendorStoreID"
	FieldNameID        = "NameID"
	FieldPlaceCode     = "PlaceCode"

	FieldCategoryID = "CategoryID"

	// FieldJdID = "JdID"
	// FieldElmID  = "ElmID"
	FieldEbaiID = "EbaiID"
	FieldMtwmID = "MtwmID"
	FieldDdID   = "DdID"
	// FieldWscID  = "WscID"
	// FieldWscID2 = "WscID2"

	FieldSkuID = "SkuID"
	FieldLevel = "Level"

	FieldEnabled     = "Enabled"
	FieldSpecQuality = "SpecQuality"
	FieldSpecUnit    = "SpecUnit"
	FieldName        = "Name"
	FieldRemark      = "Remark"

	FieldVendorOrderID  = "VendorOrderID"
	FieldVendorOrderID2 = "VendorOrderID2"

	FieldActID       = "ActID"
	FieldVendorActID = "VendorActID"

	FieldSkuSeq       = "Seq"
	FieldVendorStatus = "VendorStatus"
)

type ModelIDCUL struct {
	ID           int64     `orm:"column(id)" json:"id"`
	CreatedAt    time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
	UpdatedAt    time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
	LastOperator string    `orm:"size(32)" json:"lastOperator"` // 最后操作员
}

type ModelIDCULD struct {
	ID           int       `orm:"column(id)" json:"id"`
	CreatedAt    time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
	UpdatedAt    time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
	LastOperator string    `orm:"size(32)" json:"lastOperator"` // 最后操作员1
	DeletedAt    time.Time `orm:"type(datetime);null" json:"deletedAt"`
}

// 同步标识掩码
const (
	// general
	SyncFlagModifiedMask = 1 // 同步标志修改掩码
	SyncFlagNewMask      = 2 // 同步标记新掩码
	SyncFlagDeletedMask  = 4 // 同步标志删除掩码
	// store only
	SyncFlagStoreName    = 8  // 同步标志存储名称
	SyncFlagStoreAddress = 16 // 同步标志存储地址
	SyncFlagStoreStatus  = 32 // 同步标志存储状态

	// sku only
	SyncFlagSpecMask = 64 // 规格修改，原值32

	// store sku only
	SyncFlagSaleMask  = 8  // 改了门店商品可售状态必须设置此标志
	SyncFlagPriceMask = 16 // 改了门店商品价格必须设置此标志
	SyncFlagStockMask = 32 // 修改库存同步标识，当前只有多门店平台才会用到
	SyncFlagSeqMask   = 64 // 门店商家分类下的排序顺序

	// combine
	SyncFlagStoreSkuOnlyMask     = SyncFlagSaleMask | SyncFlagPriceMask | SyncFlagStockMask                                // 同步标志存储仅Sku掩码
	SyncFlagStoreSkuModifiedMask = SyncFlagStoreSkuOnlyMask | SyncFlagModifiedMask                                         // 同步标志存储Sku修改掩码
	SyncFlagChangedMask          = SyncFlagSpecMask | SyncFlagNewMask | SyncFlagDeletedMask | SyncFlagStoreSkuModifiedMask // 同步标志已更改掩码
)

func IsSyncStatusNew(syncStatus int8) bool {
	return (syncStatus & SyncFlagNewMask) != 0
}

func IsSyncStatusDelete(syncStatus int8) bool {
	return (syncStatus & SyncFlagDeletedMask) != 0
}

func IsSyncStatusUpdate(syncStatus int8) bool {
	return (syncStatus & SyncFlagModifiedMask) != 0
}

func IsSyncStatusSale(syncStatus int8) bool {
	return (syncStatus & SyncFlagSaleMask) != 0
}

func IsSyncStatusPrice(syncStatus int8) bool {
	return (syncStatus & SyncFlagPriceMask) != 0
}

func IsSyncStatusStock(syncStatus int8) bool {
	return (syncStatus & SyncFlagStockMask) != 0
}

func IsSyncStatusSeq(syncStatus int8) bool {
	return (syncStatus & SyncFlagSeqMask) != 0
}

func IsSyncStatusNeedCreate(syncStatus int8) bool {
	return IsSyncStatusNew(syncStatus) && !IsSyncStatusDelete(syncStatus)
}

func IsSyncStatusNeedDelete(syncStatus int8) bool {
	return !IsSyncStatusNew(syncStatus) && IsSyncStatusDelete(syncStatus)
}

func IsSyncStatusNeedUpdate(syncStatus int8) bool {
	return !IsSyncStatusNew(syncStatus) && !IsSyncStatusDelete(syncStatus) && IsSyncStatusUpdate(syncStatus)
}

// const (
// 	KeyJdFlag       = "jdFlag"
// 	KeyJdSyncedAt   = "jdSyncedAt"
// 	KeyElmFlag      = "elmFlag"
// 	KeyElmSyncedAt  = "elmSyncedAt"
// 	KeyEbaiFlag     = "ebaiFlag"
// 	KeyEbaiSyncedAt = "ebaiSyncedAt"
// )

// type ModelSyncFlag struct {
// 	JdFlag       int8      `orm:"column(jd_flag);default(2)" json:"jdFlag"`        // 京东同步状态
// 	JdSyncedAt   time.Time `orm:"column(jd_synced_at);null" json:"jdSyncedAt"`     // 京东最新成功同步时间
// 	ElmFlag      int8      `orm:"column(elm_flag);default(2)" json:"elmFlag"`      // 饿了么同步状态
// 	ElmSyncedAt  time.Time `orm:"column(elm_synced_at);null" json:"elmSyncedAt"`   // 京东最新成功同步时间
// 	EbaiFlag     int8      `orm:"column(ebai_flag);default(2)" json:"ebaiFlag"`    // 饿百同步状态
// 	EbaiSyncedAt time.Time `orm:"column(ebai_synced_at);null" json:"ebaiSyncedAt"` // 京东最新成功同步时间
// }
