package wechatrepoimpl

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

const CodeSuccess = 200

type CpnStatus string

const (
	CpnStatusAvailable = "SENDED"
	CpnStatusUsed      = "USED"
	CpnStatusExpired   = "EXPIRED"
	CpnStatusRevoked   = "REVOKED"
	CpnStatusRecover   = "RECOVER"
)

var CpnStatusTextMap = map[CpnStatus]string{
	CpnStatusAvailable: "可用",
	CpnStatusUsed:      "已实扣",
	CpnStatusExpired:   "已过期",
	CpnStatusRevoked:   "已失效",
	CpnStatusRecover:   "已回收",
}

var CpnStatusMap = map[CpnStatus]vo.OrderStatus{
	CpnStatusAvailable: vo.OrderStatusSuccess,
	CpnStatusUsed:      vo.OrderStatusUse,
	CpnStatusExpired:   vo.OrderStatusExpired,
}

func (o CpnStatus) GetText() string {
	if msg, ok := CpnStatusTextMap[o]; !ok {
		return msg
	}
	return "未知"
}

func (o CpnStatus) IsRevoked() bool {
	return o == CpnStatusRevoked
}

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