package controllers

import (
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/order"
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
	"time"
)

type OrderController struct {
	BaseController
}

//OrderStatistics 订单统计
// @router /statistics [post]
func (this *OrderController) Statistics() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.OrderStatisticsRequest
	if err := this.JsonUnmarshal(&request); err != nil {
		msg = protocol.BadRequestParam(1)
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	header := this.GetRequestHeader(this.Ctx)
	msg = protocol.NewReturnResponse(order.OrderStatistics(header, request))
}

//OrderDetail 订单详情
// @router /orderDetail [post]
func (this *OrderController) OrderDetail() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.OrderDetailRequest
	if err := this.JsonUnmarshal(&request); err != nil {
		msg = protocol.BadRequestParam(1)
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	header := this.GetRequestHeader(this.Ctx)
	msg = protocol.NewReturnResponse(order.OrderDetail(header, request))
}

//OrderList
func (this *OrderController) OrderList() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.OrderListRequest
	if err := this.JsonUnmarshal(&request); err != nil {
		msg = protocol.BadRequestParam(1)
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	request.OrderAction = domain.OrderReal
	header := this.GetRequestHeader(this.Ctx)
	msg = protocol.NewReturnResponse(order.OrderList(header, request))
}

//OrderList
func (this *OrderController) Intentions() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.OrderListRequest
	if err := this.JsonUnmarshal(&request); err != nil {
		msg = protocol.BadRequestParam(1)
		return
	}
	if b, m := this.Valid(request); !b {
		msg = m
		return
	}
	request.EndTime = time.Now().Unix() * 1000
	request.OrderAction = domain.OrderIntention
	header := this.GetRequestHeader(this.Ctx)
	msg = protocol.NewReturnResponse(order.OrderList(header, request))
}