package qixing

import (
	"fmt"
	"time"
	"voucher/internal/biz/vo"
)

type CouponState string

const (
	CouponStateUnknown CouponState = "COUPON_STATE_UNKNOW"  // 未知状态
	CouponStateSend    CouponState = "COUPON_STATE_SEND"    // 可用
	CouponStateUsed    CouponState = "COUPON_STATE_USED"    // 已实扣
	CouponStateExpired CouponState = "COUPON_STATE_EXPIRED" // 已过期
)

var CpnStatusMap = map[CouponState]vo.OrderStatus{
	CouponStateSend:    vo.OrderStatusSuccess,
	CouponStateUsed:    vo.OrderStatusUse,
	CouponStateExpired: vo.OrderStatusExpired,
}

func (o CouponState) GetStatus() (vo.OrderStatus, error) {
	if resultStatus, ok := CpnStatusMap[o]; ok {
		return resultStatus, nil
	}
	return 0, fmt.Errorf("CpnStatus[%s]未定义", o)
}

type QxQueryReq struct {
	OrderNo  string `json:"order_no"`
	CouponId string `json:"coupon_id"`
	OpenId   string `json:"open_id"`
	Sign     string `json:"sign"`
}

type QxQueryResp struct {
	Code any    `json:"code"`
	Msg  string `json:"msg"`
	Data *struct {
		StockCreatorMchID  string      `json:"stock_creator_mchid"`
		StockID            string      `json:"stock_id"`
		CouponID           string      `json:"coupon_id"`
		CouponName         string      `json:"coupon_name"`
		CouponState        CouponState `json:"coupon_state"`
		ReceiveTime        time.Time   `json:"receive_time"`
		AvailableBeginTime time.Time   `json:"available_begin_time"`
		AvailableEndTime   time.Time   `json:"available_end_time"`
		ActivityID         string      `json:"activity_id"`
		MaxUseNumber       int         `json:"max_use_number"`
		AvailableNumber    int         `json:"available_number"`
		UsedNumber         int         `json:"used_number"`
		UseAmountList      struct {
			UsedAmounts []string `json:"used_amounts"`
		} `json:"use_amount_list"`
		OpenID string `json:"openid"`
	} `json:"data"`
}
