package tao_vegetable

// StoreTokenInfo 信息解析
type StoreTokenInfo struct {
	W2Valid               int64  `json:"w2_valid"`
	R1Valid               int64  `json:"r1_valid"`
	Sp                    string `json:"sp"`
	R2Valid               int64  `json:"r2_valid"`
	W1Valid               int64  `json:"w1_valid"`
	Locale                string `json:"locale"`
	UserId                string `json:"user_id"`
	ExpireTime            int64  `json:"expire_time"`
	RefreshToken          string `json:"refresh_token"`
	UserNick              string `json:"user_nick"`
	RefreshTokenValidTime int64  `json:"refresh_token_valid_time"`
	AccessToken           string `json:"access_token"`
}

// VegetableResultList 创建更新时,同意返回结构
type VegetableResultList struct {
	ProductID string `json:"product_id"`
	SkuID     string `json:"sku_id"`
	ErrMsg    string `json:"err_msg"`
}

// CallBackResult 回调函数同意返回结构
type CallBackResult struct {
	Success bool   `json:"success"`
	ErrCode string `json:"errCode"` // SUCCESS/Fail
	ErrMsg  string `json:"errMsg"`  // 文字说明
}

// CallBackResultInfo 失败回调返回
func CallBackResultInfo(err error) *CallBackResult {
	if err == nil {
		return &CallBackResult{
			Success: true,
			ErrCode: "SUCCESS",
			ErrMsg:  "成功",
		}
	}
	return &CallBackResult{
		Success: false,
		ErrCode: "FAIL",
		ErrMsg:  err.Error(),
	}
}

// CallBackResultSign 签名错误
func CallBackResultSign(err error) *CallBackResult {
	if err == nil {
		return &CallBackResult{
			Success: true,
			ErrCode: "SUCCESS",
			ErrMsg:  "成功",
		}
	}

	return &CallBackResult{
		Success: false,
		ErrCode: "sign-check-failure",
		ErrMsg:  err.Error(),
	}
}

// CallBackResultOnSaleCancel 售中取消允许开关
func CallBackResultOnSaleCancel(err error) *CallBackResult {
	if err == nil {
		return &CallBackResult{
			Success: true,
			ErrCode: "SUCCESS",
			ErrMsg:  "成功",
		}
	}
	return &CallBackResult{
		Success: false,
		ErrCode: "NOT_SUPPORT_INSALE_CANCEL",
		ErrMsg:  "不支持售中取消。",
	}
}
