package businesserr

// 公共 & 业务错误码常量（统一定义，前缀 MULTI_）
// https://pay.weixin.qq.com/doc/v3/merchant/4012463767
const (
	MULTI_PARAM_ERROR           ErrCode = "PARAM_ERROR"           // 参数错误（如缺少必填字段）
	MULTI_INVALID_REQUEST       ErrCode = "INVALID_REQUEST"       // 非法请求（如 OpenID 与 AppID 不匹配、批次状态异常等）
	MULTI_SIGN_ERROR            ErrCode = "SIGN_ERROR"            // 签名验证失败
	MULTI_SYSTEM_ERROR          ErrCode = "SYSTEM_ERROR"          // 系统异常
	MULTI_APPID_MCHID_NOT_MATCH ErrCode = "APPID_MCHID_NOT_MATCH" // 商户号与 AppID 不匹配
	MULTI_MCH_NOT_EXISTS        ErrCode = "MCH_NOT_EXISTS"        // 商户号不合法
	MULTI_NOT_ENOUGH            ErrCode = "NOT_ENOUGH"            // 资源不足（预算/余额/限额耗尽）
	MULTI_REQUEST_BLOCKED       ErrCode = "REQUEST_BLOCKED"       // 请求被拦截（跨商户、渠道限制等）
	MULTI_RULE_LIMIT            ErrCode = "RULE_LIMIT"            // 用户或自然人达到领取上限
	MULTI_USER_ACCOUNT_ABNORMAL ErrCode = "USER_ACCOUNT_ABNORMAL" // 用户账号异常（风控、未实名等）
	MULTI_RESOURCE_NOT_EXISTS   ErrCode = "RESOURCE_NOT_EXISTS"   // 批次不存在
)

// MULTIAPIErrorMap 定义错误映射，方便根据错误码获取所有可能的错误场景
var CmbMULTIAPIErrorMap = map[ErrCode][]CmbAPIError{
	MULTI_SYSTEM_ERROR: {
		{
			StatusCode:   500,
			ErrorCode:    MULTI_SYSTEM_ERROR,
			Description:  "系统异常，请稍后重试",
			Hint:         "请稍后重试",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
	MULTI_SIGN_ERROR: {
		{
			StatusCode:   401,
			ErrorCode:    MULTI_SIGN_ERROR,
			Description:  "验证不通过",
			Hint:         "请参阅 签名常见问题",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
	MULTI_APPID_MCHID_NOT_MATCH: {
		{
			StatusCode:   400,
			ErrorCode:    MULTI_APPID_MCHID_NOT_MATCH,
			Description:  "商户号与AppID不匹配",
			Hint:         "调用接口的商户号需与接口传入的AppID有绑定关系，请参考常见问题Q4",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
	MULTI_INVALID_REQUEST: {
		{
			StatusCode:   400,
			ErrorCode:    MULTI_INVALID_REQUEST,
			Description:  "HTTP 请求不符合微信支付 APIv3 接口规则",
			Hint:         "请参阅 接口规则",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   400,
			ErrorCode:    MULTI_INVALID_REQUEST,
			Description:  "非法的商户号",
			Hint:         "请检查商户号准确性",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   400,
			ErrorCode:    MULTI_INVALID_REQUEST,
			Description:  "OpenID与AppID不匹配",
			Hint:         "OpenID与AppID需有对应关系",
			ThirdErrCode: ThirdErrCodeAppIDOpenIDMismatch,
		},
	},
	MULTI_PARAM_ERROR: {
		{
			StatusCode:   400,
			ErrorCode:    MULTI_PARAM_ERROR,
			Description:  "参数错误",
			Hint:         "请根据错误提示正确传入参数",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   400,
			ErrorCode:    MULTI_PARAM_ERROR,
			Description:  "AppID必填",
			Hint:         "请输入AppID",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   400,
			ErrorCode:    MULTI_PARAM_ERROR,
			Description:  "OpenID必填",
			Hint:         "请输入OpenID",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   400,
			ErrorCode:    MULTI_PARAM_ERROR,
			Description:  "批次号必填",
			Hint:         "请输入批次号",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   400,
			ErrorCode:    MULTI_PARAM_ERROR,
			Description:  "商户号必填",
			Hint:         "请输入商户号",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
	MULTI_MCH_NOT_EXISTS: {
		{
			StatusCode:   403,
			ErrorCode:    MULTI_MCH_NOT_EXISTS,
			Description:  "商户号不合法",
			Hint:         "请检查商户号准确性",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
	MULTI_NOT_ENOUGH: {
		{
			StatusCode:   403,
			ErrorCode:    MULTI_NOT_ENOUGH,
			Description:  "批次预算耗尽",
			Hint:         "该批次的预算已经耗尽",
			ThirdErrCode: ThirdErrCodeAdvanceFundingNotEnough,
		},
		{
			StatusCode:   403,
			ErrorCode:    MULTI_NOT_ENOUGH,
			Description:  "账户余额不足，请充值",
			Hint:         "商户号余额不足，无法继续发券，请充值",
			ThirdErrCode: ThirdErrCodeAdvanceFundingNotEnough,
		},
		{
			StatusCode:   403,
			ErrorCode:    MULTI_NOT_ENOUGH,
			Description:  "发券超过单天限额",
			Hint:         "已超过该批次设置的单天发放限制额度，无法发放",
			ThirdErrCode: ThirdErrCodeDailyLimit,
		},
	},
	MULTI_REQUEST_BLOCKED: {
		{
			StatusCode:   403,
			ErrorCode:    MULTI_REQUEST_BLOCKED,
			Description:  "参数错误，请检查批次参数",
			Hint:         "活动未开始或已结束",
			ThirdErrCode: ThirdErrCodeBatchNotStarted, // 时间前置判断一下
		},
		{
			StatusCode:   403,
			ErrorCode:    MULTI_REQUEST_BLOCKED,
			Description:  "仅在广告场景下发放批次",
			Hint:         "该批次已在朋友圈广告发放，不支持在其他渠道发放",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   403,
			ErrorCode:    MULTI_REQUEST_BLOCKED,
			Description:  "商户号收款功能受限，无法发券",
			Hint:         "商户号收款功能受限",
			ThirdErrCode: ThirdErrCodeDefault,
		},
		{
			StatusCode:   403,
			ErrorCode:    MULTI_REQUEST_BLOCKED,
			Description:  "批次不支持跨商户发券",
			Hint:         "该批次不支持其他商户发放",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
	MULTI_RULE_LIMIT: {
		{
			StatusCode:   403,
			ErrorCode:    MULTI_RULE_LIMIT,
			Description:  "用户已达最大领券次数",
			Hint:         "该用户已达到该批次的领取上限",
			ThirdErrCode: ThirdErrCodeUserParticipationExceeded,
		},
	},
	MULTI_USER_ACCOUNT_ABNORMAL: {
		{
			StatusCode:   403,
			ErrorCode:    MULTI_USER_ACCOUNT_ABNORMAL,
			Description:  "用户未实名",
			Hint:         "该用户无实名信息，无法领券。商家可联系微信支付或让用户联系微信支付客服处理。",
			ThirdErrCode: ThirdErrCodeUserNotRealNameVerified,
		},
	},
	MULTI_RESOURCE_NOT_EXISTS: {
		{
			StatusCode:   404,
			ErrorCode:    MULTI_RESOURCE_NOT_EXISTS,
			Description:  "批次不存在",
			Hint:         "请检查批次及制券商户号信息",
			ThirdErrCode: ThirdErrCodeDefault,
		},
	},
}
