package redeem

import (
	"kami/internal/consts"
	"kami/utility/integration/redeem"
)

type ServiceOneCommonResponse struct {
	Code CallbackResponseStatus `json:"code"`
	Data struct {
		Code string `json:"code"`
		Data struct {
			CardTypeName string  `json:"cardTypeName"`
			GiftCardId   string  `json:"giftCardId"`
			Amount       float64 `json:"amount"`
			AmountTotal  float64 `json:"amountTotal"`
			IsBind       string  `json:"IsBind"`
		} `json:"data"`
	} `json:"data"`
}

func (s *ServiceOneCommonResponse) MapResult(rawData string) *redeem.BindCardOutput {
	res := &redeem.BindCardOutput{
		RawData: rawData,
		Amount:  0,
	}
	switch s.Code {
	case CallbackResponseStatusSucceed:
		res.Status = consts.RedeemOrderSuccess
		res.Amount = s.Data.Data.Amount
	case CallbackResponseStatusWrongCardType:
		res.Status = consts.RedeemOrderFailWithWrongCardType
	case CallbackResponseStatusClickValidatedFail:
		res.Status = consts.RedeemOrderRefundWithValidatedFail
	case CallBackResponseStatusCkFail:
		res.Status = consts.RedeemOrderFailWithCKFail
	case CallbackResponseStatusAccountFrequent:
		res.Status = consts.RedeemOrderFailWithFrequent
	case CallbackResponseStatusCkNotFound:
		res.Status = consts.RedeemOrderFailCardNotExist
	case CallbackResponseStatusAlreadyConsumed:
		res.Status = consts.RedeemOrderFailWithOtherBind
	case CallbackResponseStatusNotSafe:
		res.Status = consts.RedeemOrderFail
	case CallbackResponseStatusCardNotActive:
		res.Status = consts.RedeemOrderFailCardNotExist
	case CallbackResponseStatusCardFreeze:
		res.Status = consts.RedeemOrderFailWithFrozen
	case CallbackResponseStatusCardUnknown:
		res.Status = consts.RedeemOrderFailWithCardUnknown
	case CallbackResponseStatusWrongAmount:
		res.Status = consts.RedeemOrderFailWithDifferentAmount
	default:
		res.Status = consts.RedeemOrderFailWithCardUnknown
	}
	return res
}

type QueryBalanceInfo struct {
	Id    string  `json:"id"`
	Ck    string  `json:"ck"`
	Money float64 `json:"money"`
	IsOk  bool    `json:"is_ok"`
}

type QueryUserInfo struct {
	NickName string `json:"nick_name"`
	Username string `json:"username"`
	Ok       bool   `json:"ok"`
}

type CommonResponse[T interface{}] struct {
	Code int `json:"code"`
	Data T   `json:"data"`
}
