package consts

// ====================================================================================
// 京东Cookie管理模块常量定义
// ====================================================================================

// JdCookieStatus Cookie账户状态枚举
type JdCookieStatus int

const (
	JdCookieStatusUnknown JdCookieStatus = 0 // 未知状态（用于删除等场景）
	JdCookieStatusNormal  JdCookieStatus = 1 // 正常
	JdCookieStatusSuspend JdCookieStatus = 2 // 暂停
	JdCookieStatusExpired JdCookieStatus = 3 // 失效
)

// JdCookieStatusText Cookie状态文本映射
var JdCookieStatusText = map[JdCookieStatus]string{
	JdCookieStatusNormal:  "正常",
	JdCookieStatusSuspend: "暂停",
	JdCookieStatusExpired: "失效",
	JdCookieStatusUnknown: "未知",
}

// JdOrderStatus 京东订单状态枚举
type JdOrderStatus int

const (
	JdOrderStatusPending  JdOrderStatus = 1 // 待支付
	JdOrderStatusPaid     JdOrderStatus = 2 // 已支付
	JdOrderStatusSent     JdOrderStatus = 3 // 已发货
	JdOrderStatusExpired  JdOrderStatus = 4 // 已过期
	JdOrderStatusCanceled JdOrderStatus = 5 // 已取消
	JdOrderStatusCkFailed JdOrderStatus = 6 // Ck失败
)

// JdOrderStatusText 京东订单状态文本映射
var JdOrderStatusText = map[JdOrderStatus]string{
	JdOrderStatusPending:  "待支付",
	JdOrderStatusPaid:     "已支付",
	JdOrderStatusExpired:  "已过期",
	JdOrderStatusCanceled: "已取消",
	JdOrderStatusCkFailed: "Ck失败",
	JdOrderStatusSent:     "已发货",
}

// OrderStatus 订单状态枚举（与京东订单状态相同）
type OrderStatus int

const (
	OrderStatusCreated       OrderStatus = 0 // 创建
	OrderStatusPending       OrderStatus = 1 // 待支付
	OrderStatusPaid          OrderStatus = 2 // 已支付
	OrderStatusExpired       OrderStatus = 3 // 已过期
	OrderStatusCanceled      OrderStatus = 4 // 已取消
	OrderStatusCkFailed      OrderStatus = 5 // cookie失效
	OrderStatusJDOrderFailed OrderStatus = 6 // 下单京东订单失败
	OrderStatusStockFailed   OrderStatus = 7 // 库存问题
)

// OrderStatusText 订单状态文本映射
var OrderStatusText = map[OrderStatus]string{
	OrderStatusCreated:       "创建",
	OrderStatusPending:       "待支付",
	OrderStatusPaid:          "已支付",
	OrderStatusExpired:       "已过期",
	OrderStatusCanceled:      "已取消",
	OrderStatusCkFailed:      "cookie失效",
	OrderStatusJDOrderFailed: "下单京东订单失败",
	OrderStatusStockFailed:   "库存问题",
}

// ====================================================================================
// 变更类型常量定义
// ====================================================================================

// CookieChangeType Cookie变更类型
type CookieChangeType string

const (
	CookieChangeTypeCreate      CookieChangeType = "create"       // 创建
	CookieChangeTypeSuspend     CookieChangeType = "suspend"      // 暂停
	CookieChangeTypeResume      CookieChangeType = "resume"       // 恢复
	CookieChangeTypeFail        CookieChangeType = "fail"         // 失败
	CookieChangeTypeUse         CookieChangeType = "use"          // 使用
	CookieChangeTypeRefreshFail CookieChangeType = "refresh fail" // 刷新失败
	CookieChangeTypeReplaced    CookieChangeType = "replaced"     // 被替换（新增）
	CookieChangeTypeDelete      CookieChangeType = "delete"       // 删除
	CookieChangeTypeUpdate      CookieChangeType = "update"       // 更新
	CookieChangeTypeBatchDelete CookieChangeType = "batch delete" // 批量删除失效Cookie
)

// JdOrderChangeType 京东订单变更类型
type JdOrderChangeType string

const (
	JdOrderChangeTypeCreate   JdOrderChangeType = "create"   // 创建
	JdOrderChangeTypeBind     JdOrderChangeType = "bind"     // 绑定
	JdOrderChangeTypeUnbind   JdOrderChangeType = "unbind"   // 解绑
	JdOrderChangeTypePendPay  JdOrderChangeType = "pendPay"  // 待支付
	JdOrderChangeTypePay      JdOrderChangeType = "pay"      // 支付
	JdOrderChangeTypeExpire   JdOrderChangeType = "expire"   // 过期
	JdOrderChangeTypeInvalid  JdOrderChangeType = "invalid"  // 失效（新增）
	JdOrderChangeTypeSend     JdOrderChangeType = "send"     // 发货
	JdOrderChangeTypeReplace  JdOrderChangeType = "replace"  // 换绑
	JdOrderChangeTypeCallback JdOrderChangeType = "callback" // 回调
)

// JdOrderChangeTypeText 京东订单变更类型文本映射
var JdOrderChangeTypeText = map[JdOrderChangeType]string{
	JdOrderChangeTypeCreate:   "创建",
	JdOrderChangeTypeBind:     "绑定",
	JdOrderChangeTypeUnbind:   "解绑",
	JdOrderChangeTypePay:      "支付",
	JdOrderChangeTypeExpire:   "过期",
	JdOrderChangeTypeInvalid:  "失效",
	JdOrderChangeTypeSend:     "发货",
	JdOrderChangeTypeReplace:  "换绑",
	JdOrderChangeTypePendPay:  "待支付",
	JdOrderChangeTypeCallback: "回调",
}

// OrderChangeType 订单变更类型
type OrderChangeType string

const (
	OrderChangeTypeCreate        OrderChangeType = "create"          // 创建
	OrderChangeTypePay           OrderChangeType = "pay"             // 支付
	OrderChangeTypeExpire        OrderChangeType = "expire"          // 过期
	OrderChangeTypeBind          OrderChangeType = "bind"            // 重新绑定
	OrderChangeTypeCkFailed      OrderChangeType = "ck_failed"       // Ck失败
	OrderChangeTypeJDOrderFailed OrderChangeType = "jd_order_failed" //下单京东订单失败
	OrderChangeTypeStockFailed   OrderChangeType = "stock_failed"    // 库存问题
	OrderChangeTypeCallback      OrderChangeType = "callback"
)

// OrderChangeTypeText 订单变更类型文本映射
var OrderChangeTypeText = map[OrderChangeType]string{
	OrderChangeTypeCreate:        "创建",
	OrderChangeTypePay:           "支付",
	OrderChangeTypeExpire:        "过期",
	OrderChangeTypeBind:          "绑定",
	OrderChangeTypeCkFailed:      "cookie失败",
	OrderChangeTypeJDOrderFailed: "下单京东订单失败",
	OrderChangeTypeStockFailed:   "库存问题",
	OrderChangeTypeCallback:      "回调",
}

// ====================================================================================
// 业务配置常量
// ====================================================================================

const (
	// JdCookieMaxFailureCount Cookie最大失败次数，超过后标记为失效
	JdCookieMaxFailureCount = 3

	// JdCookieSuspendDuration Cookie暂停时长（分钟）
	JdCookieSuspendDuration = 10

	// JdOrderExpireDuration 京东订单过期时间（小时）
	JdOrderExpireDuration = 24

	// WxPayUrlExpireDuration 微信支付链接过期时间（分钟）
	WxPayUrlExpireDuration = 3

	// OrderReuseTimeout 订单复用超时时间（分钟）
	OrderReuseTimeout = 15

	// JdOrderReuseTimeout 京东订单复用超时时间（分钟）
	JdOrderReuseTimeout = 30

	// CookieRotationKey Redis中Cookie轮询索引的键名
	CookieRotationKey = "jd_cookie:rotation:index"

	// CookieAvailableKey Redis中可用Cookie列表的键名
	CookieAvailableKey = "jd_cookie:available:list"

	// OrderLockKeyPrefix 订单创建锁的键名前缀
	OrderLockKeyPrefix = "jd_cookie:order:lock:"

	// CookieLockKeyPrefix Cookie分配锁的键名前缀
	CookieLockKeyPrefix = "jd_cookie:cookie:lock:"
)

// ====================================================================================
// 错误码常量
// ====================================================================================

const (
	// ErrCodeCookieNotFound Cookie不存在
	ErrCodeCookieNotFound = "COOKIE_NOT_FOUND"

	// ErrCodeCookieNotAvailable 没有可用的Cookie
	ErrCodeCookieNotAvailable = "COOKIE_NOT_AVAILABLE"

	// ErrCodeOrderNotFound 订单不存在
	ErrCodeOrderNotFound = "ORDER_NOT_FOUND"

	// ErrCodeOrderAlreadyExists 订单已存在
	ErrCodeOrderAlreadyExists = "ORDER_ALREADY_EXISTS"

	// ErrCodeJdOrderNotFound 京东订单不存在
	ErrCodeJdOrderNotFound = "JD_ORDER_NOT_FOUND"

	// ErrCodePaymentUrlExpired 支付链接已过期
	ErrCodePaymentUrlExpired = "PAYMENT_URL_EXPIRED"

	// ErrCodeOrderCannotReuse 订单无法复用
	ErrCodeOrderCannotReuse = "ORDER_CANNOT_REUSE"

	// ErrCodeCookieAlreadyExpired Cookie已失效
	ErrCodeCookieAlreadyExpired = "COOKIE_ALREADY_EXPIRED"

	// ErrCodeSystemBusy 系统繁忙
	ErrCodeSystemBusy = "SYSTEM_BUSY"
)
