package forms

import (
	"errors"
	"time"
)

type OrderSettleListReq struct {
	ListReq
	Platform  int32   `json:"platform" form:"platform"`
	UserId    int64   `json:"user_id" form:"user_id"`
	OrderSn   string  `json:"order_sn" form:"order_sn"`
	Status    int32   `json:"status" form:"status"`
	CreatedAt []int64 `json:"created_at" form:"created_at[]"`
	Time      []time.Time
}

func (req *OrderSettleListReq) Check() error {
	if req.CreatedAt != nil && len(req.CreatedAt) != 2 {
		return errors.New("创建时间必须选择一个区间或者留空")
	}

	if len(req.CreatedAt) == 2 {
		if req.CreatedAt[0] > req.CreatedAt[1] {
			return errors.New("注册时间选择的区间值不合理")
		}
		// 默认是毫秒
		req.Time = append(req.Time, time.Unix(req.CreatedAt[0]/1000, 0))
		req.Time = append(req.Time, time.Unix(req.CreatedAt[1]/1000, 0))
	}

	return nil
}

type OrderSettleListRes struct {
	ListRes
}
