package vo

import "fmt"

type OrderStatus uint8

const (
	OrderStatusWait OrderStatus = iota + 1
	OrderStatusIng
	OrderStatusSuccess
	OrderStatusFail
	OrderStatusUse
	OrderStatusExpired
)

var OrderStatusMap = map[OrderStatus]string{
	OrderStatusWait:    "待发放",
	OrderStatusIng:     "发放中",
	OrderStatusSuccess: "发放成功",
	OrderStatusFail:    "发放失败",
	OrderStatusUse:     "已使用",
	OrderStatusExpired: "已过期",
}

func (s OrderStatus) GetText() string {
	if t, ok := OrderStatusMap[s]; ok {
		return t
	}
	return "未知状态"
}

func (s OrderStatus) GetValue() uint8 {
	return uint8(s)
}

func (s OrderStatus) IsWait() bool {
	return s == OrderStatusWait
}

func (s OrderStatus) IsIng() bool {
	return s == OrderStatusIng
}

func (s OrderStatus) IsSuccess() bool {
	return s == OrderStatusSuccess
}

func (s OrderStatus) IsFail() bool {
	return s == OrderStatusFail
}

func (s OrderStatus) IsUse() bool {
	return s == OrderStatusUse
}

func (s OrderStatus) IsExpired() bool {
	return s == OrderStatusExpired
}

func (s OrderStatus) IsCanNotify() bool {
	return s.IsSuccess() || s.IsUse() || s.IsExpired()
}

var OrderStatusMapOrderNotifyEvent = map[OrderStatus]OrderNotifyEvent{
	OrderStatusSuccess: OrderNotifyEventSendDEd,
	OrderStatusUse:     OrderNotifyEventUsed,
	OrderStatusExpired: OrderNotifyEventExpired,
}

func (s OrderStatus) GetOrderNotifyEvent() (OrderNotifyEvent, error) {
	if t, ok := OrderStatusMapOrderNotifyEvent[s]; ok {
		return t, nil
	}
	return 0, fmt.Errorf("CmbStatus[%s]未定义", s)
}

var OrderStatusMapCmbStatus = map[OrderStatus]CmbStatus{
	OrderStatusSuccess: CmbStatusSuccess,
	OrderStatusUse:     CmbStatusUse,
	OrderStatusExpired: CmbStatusExpired,
}

func (s OrderStatus) GetCmbStatusText() (CmbStatus, error) {
	if t, ok := OrderStatusMapCmbStatus[s]; ok {
		return t, nil
	}
	return "", fmt.Errorf("cmbStatus[%s]未定义", s)
}
