package controller

import (
	"cold-delivery/app/admin/model"
	"cold-delivery/app/admin/service"
	"cold-delivery/app/admin/service/dto"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"gogs.baozhida.cn/zoie/OAuth-core/api"
	_ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
)

type WaybillLogisticsController struct {
	api.Api
}

// GetPage 获取运单列表
// @Summary 获取运单列表
// @Description 获取运单列表
// @Tags 运单
// @Param waybillNo query string true "运单号"
// @Param status query string false "状态"
// @Success 200 {object} response.Response{data=response.Page{list=[]model.WaybillLogistics}} "{"code": 200, "data": [...]}"
// @Router /api/waybill [get]
// @Security Bearer
func (e WaybillLogisticsController) GetPage(c *gin.Context) {
	s := service.WaybillLogistics{}
	req := dto.WaybillLogisticsGetPageReq{}
	err := e.MakeContext(c).
		MakeOrm().
		Bind(&req, binding.Query).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	list := make([]model.WaybillLogistics, 0)
	var count int64

	err = s.GetPage(&req, &list, &count)
	if err != nil {
		e.Error(500, err, err.Error())
		return
	}
	e.PageOK(list, int(count), 0, 0, "查询成功")
}
