package model

// VendorIDJD, VendorIDMTWM与VendorIDELM的定义和老系统是兼容的
const (
	VendorTypeUnknown  = 0 // 未知
	VendorTypePurchase = 1 // 购物平台
	VendorTypeDelivery = 2 // 快递平台
	VendorTypePrinter  = 3 // 网络打印机
	VendorTypeOthers   = 9 // 其它

	VendorIDUnknown       = -1
	VendorIDPurchaseBegin = 0
	VendorIDJD            = 0
	VendorIDMTWM          = 1
	VendorIDELM           = 2
	VendorIDEBAI          = 3
	VendorIDYB            = 4 //银豹
	VendorIDJDShop        = 5 //京东商城
	VendorIDJX            = 9 // 这是一个假的京西VendorID
	VendorIDGD            = 10
	VendorIDWSC           = 11 // 微盟微商城
	VendorGoMei           = 12 // 国美
	VendorIDTT            = 13 // 抖音平台小程序
	VendorIDDD            = 14 // 抖店
	VendorIDKS            = 15 // 快手小程序
	VendorIDTaoVegetable  = 16 // 淘鲜达(淘菜菜)
	VendorIDPurchaseEnd   = 20

	VendorIDWXPay = 51 // 微信支付

	VendorIDDeliveryBegin = 101
	VendorIDDada          = 101 // 达达配送
	VendorIDMTPS          = 102 // 美团配送
	VendorIDFengNiao      = 103 // 蜂鸟配送
	//VendorIDDYPS          = 104 // 抖音配送
	VendorIDUUPT        = 105 //uu跑腿
	VendorIDSFPS        = 106 //顺丰派送
	VendorJXFakeWL      = 300 // 京西假物流
	VendorIDJDWL        = 401 // 京东物流
	VendorIDTotalWl     = 402 // (综合物流[京东,圆通,申通....])
	VendorIDDeliveryEnd = 500

	VendorIDPrinterBegin = 201
	VendorIDFeiE         = 201 // 飞鹅打印机
	VendorIDXiaoWM       = 202 // 外卖管家打印机
	VendorIDYiLianYun    = 203 // 易联云
	VendorIDZhongWu      = 204 // 中午云打印
	VendorIDJxprint      = 205 // 京西打印
	VendorIDXpYun        = 206 // 芯烨云打印机
	VendorIDTrendIT      = 207 //大趋智能
	VendorIDPrinterEnd   = 300

	VendorIDOthersBegin = 301

	VendorIDWXMP     = 301 // 微信公众号
	VendorIDWXQRCode = 302 // 微信扫码
	VendorIDWXMini   = 303 // 微信小程序

	VendorIDDDH5MicroApp   = 311 // 钉钉H5微应用
	VendorIDDDMobileQRCode = 312 // 钉钉移动接入应用（登录）

	VendorIDAutonavi      = 321 // 高德导航
	VendorIDQiNiuCloud    = 323 // 七牛云
	VendorIDShowAPI       = 325 // 万维易源
	WayBillDeliveryMarkUp = 20  // 运单加价两毛钱

)
const BrandIdChengShan = 142 // 成山农场品牌id

const (
	DefMaxDeliveryFee = 1500 // 创建运单最高价
	AlarmFee          = 1500 // 配送费报警阈值
)

const (
	InvoiceStatusInit           = "1" // INIT-初始化，未受理
	InvoiceStatusFailUre        = "2" // APPLY_FAILURE-申请受理失败
	InvoiceStatusBilling        = "3" // 开具中
	InvoiceStatusBillingSuccess = "4" // 开具成功
	InvoiceStatusBillingFail    = "5" // 开具失败
)

type VendorInfo struct {
	Name string `json:"name"`

	OrgCodeName string `json:"orgCodeName"`
	Value1Name  string `json:"value1Name,omitempty"`
	Value2Name  string `json:"value2Name,omitempty"`
	Value3Name  string `json:"value3Name,omitempty"`
	Value4Name  string `json:"value4Name,omitempty"`
	Value5Name  string `json:"value5Name,omitempty"`
}

var (
	VendorNames = map[int]string{
		VendorIDJD:           "Jd",
		VendorIDMTWM:         "Mtwm",
		VendorIDDD:           "Dd", // 抖店
		VendorIDELM:          "Elm",
		VendorIDEBAI:         "Ebai",
		VendorIDWSC:          "Wsc",
		VendorIDYB:           "Yb",
		VendorIDJX:           "Jx",
		VendorIDJDShop:       "Jds",
		VendorIDTaoVegetable: "Tao",

		VendorIDDada:     "Dada",
		VendorIDMTPS:     "Mtps",
		VendorIDFengNiao: "Fn",
		VendorIDSFPS:     "Sfps",
		VendorIDUUPT:     "UUPT",

		VendorIDFeiE:      "Feie",
		VendorIDXiaoWM:    "XiaoWM",
		VendorIDYiLianYun: "Yilianyun",
		VendorIDZhongWu:   "ZhongWu",
		VendorIDJxprint:   "Jx",
		VendorIDXpYun:     "Xpyun",
		VendorIDTrendIT:   "TrendIT",

		VendorIDQiNiuCloud: "Qiniu",
		VendorIDJDWL:       "Jdwl",
	}

	VendorTypeName = map[int]string{
		VendorTypeUnknown:  "未知",
		VendorTypePurchase: "购物平台",
		VendorTypeDelivery: "快递平台",
		VendorTypeOthers:   "其它",
	}

	VendorChineseNames = map[int]string{
		VendorIDJD:           "京东到家",
		VendorIDMTWM:         "美团外卖",
		VendorIDELM:          "饿了么",
		VendorIDEBAI:         "淘宝闪购",
		VendorIDYB:           "银豹",
		VendorIDJDShop:       "京东商城",
		VendorIDWSC:          "微盟微商城",
		VendorIDJX:           "京西商城",
		VendorIDTaoVegetable: "淘鲜达",

		VendorIDDada:     "达达众包",
		VendorIDMTPS:     "美团配送",
		VendorIDJDWL:     "京东物流",
		VendorIDFengNiao: "蜂鸟配送",
		VendorIDSFPS:     "顺丰派送",
		//VendorIDDYPS:     "抖音配送",
		VendorIDUUPT: "UU跑腿",

		VendorIDFeiE:      "飞鹅",
		VendorIDXiaoWM:    "外卖管家",
		VendorIDYiLianYun: "易联云",
		VendorIDZhongWu:   "中午云",
		VendorIDJxprint:   "京西云",
		VendorIDXpYun:     "芯烨云",
		VendorIDTrendIT:   "大趋智能",

		VendorIDWXMP:     "微信公众号",
		VendorIDWXQRCode: "微信扫码",
		VendorIDWXMini:   "微信小程序",

		VendorIDDDH5MicroApp:   "钉钉H5微应用",
		VendorIDDDMobileQRCode: "钉钉移动接入应用（登录）",

		VendorIDAutonavi:   "高德导航",
		VendorIDQiNiuCloud: "七牛云",
		VendorIDShowAPI:    "万维易源",
		VendorGoMei:        "国美",
		VendorIDDD:         "抖店平台",
	}

	VendorInfoMap = map[int]*VendorInfo{
		VendorIDJD: &VendorInfo{
			Name:        "京东到家",
			OrgCodeName: "商户代码",
			Value1Name:  "AppKey",
			Value2Name:  "AppSecret",
			Value3Name:  "Token",
			Value4Name:  "管理后台Cookie",
		},
		VendorIDMTWM: &VendorInfo{
			Name:        "美团外卖",
			OrgCodeName: "AppID",
			Value1Name:  "Secret",
			Value2Name:  "回调URL",
		},
		VendorIDEBAI: &VendorInfo{
			Name:        "饿百联盟",
			OrgCodeName: "商户代码",
			Value1Name:  "Source",
			Value2Name:  "Secret",
			Value3Name:  "管理后台Cookie",
		},

		// VendorIDDada: &VendorInfo{
		// 	Name:        "达达快递",
		// 	OrgCodeName: "商户ID",
		// 	Value1Name:  "app_key",
		// 	Value2Name:  "app_secret",
		// },
		// VendorIDMTPS: &VendorInfo{
		// 	Name:        "美团配送",
		// 	OrgCodeName: "自编码",
		// 	Value1Name:  "Appkey",
		// 	Value2Name:  "Secret",
		// },

		// VendorIDFeiE: &VendorInfo{
		// 	Name:        "飞鹅",
		// 	OrgCodeName: "User",
		// 	Value1Name:  "Key",
		// },
		// VendorIDXiaoWM: &VendorInfo{
		// 	Name:        "外卖管家",
		// 	OrgCodeName: "AppID",
		// 	Value1Name:  "AppKey",
		// },
		// VendorIDYiLianYun: &VendorInfo{
		// 	Name:        "易联云",
		// 	OrgCodeName: "ClientID",
		// 	Value1Name:  "ClientSecret",
		// },
	}
)

func GetVendorMask(vendorIDs ...int) (vendorMask int) {
	for _, vendorID := range vendorIDs {
		vendorMask |= 1 << uint(vendorID)
	}
	return vendorMask
}

func GetVendorType(vendorID int) (vendorType int) {
	if vendorID >= VendorIDPurchaseBegin && VendorIDPurchaseBegin <= VendorIDPurchaseEnd {
		return VendorTypePurchase
	} else if vendorID >= VendorIDPurchaseBegin && VendorIDPurchaseBegin <= VendorIDPurchaseEnd {
		return VendorTypeDelivery
	} else if vendorID >= VendorIDOthersBegin {
		return VendorTypeOthers
	}
	return VendorTypeUnknown
}

type AppKeyConfig struct {
	ModelIDCULD
	VendorID      int    `json:"vendorID"`
	VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码，如果只有一个，可以为空

	Name   string `orm:"size(32)" json:"name"`
	Value1 string `orm:"size(1024)" json:"value1"`
	Value2 string `orm:"size(1024)" json:"value2"`
	Value3 string `orm:"size(1024)" json:"value3"`
	Value4 string `orm:"size(1024)" json:"value4"`
	Value5 string `orm:"size(1024)" json:"value5"`
}

func (a *AppKeyConfig) TableUnique() [][]string {
	return [][]string{
		[]string{"VendorID", "VendorOrgCode", "DeletedAt"},
	}
}
