package jd_cookie

import (
	"context"
	"kami/api/jd_cookie/v1"
	"kami/internal/errHandler"
	"kami/internal/service"

	"github.com/gogf/gf/v2/errors/gcode"
)

func (c *ControllerV1) GetJdOrderHistory(ctx context.Context, req *v1.GetJdOrderHistoryReq) (res *v1.GetJdOrderHistoryRes, err error) {
	_, err = service.SysAuth().LoginOnlyIFrame(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}
	list, total, err := service.JdCookie().GetJdOrderHistoryByJdOrderId(ctx, req.JdOrderId, req.Page, req.Size)
	if err != nil {
		return nil, err
	}

	res = &v1.GetJdOrderHistoryRes{
		List:  list,
		Total: total,
	}

	return res, nil
}
