package logic

import (
	"context"
	"jyBXBuyer/rpc/type/bxbuyer"
	"net/http"

	"jyBXBuyer/api/internal/svc"
	"jyBXBuyer/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BuyerSearchListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewBuyerSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *BuyerSearchListLogic {
	return &BuyerSearchListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
		r:      r,
	}
}

func (l *BuyerSearchListLogic) BuyerSearchList(req *types.BuyerListReq) (resp *types.CommonResp, err error) {
	if req.EntUserId == "" {
		req.IsCheckReceive = false
	}
	if req.UserId == "" {
		req.IsCheckFollow = false
	}
	res, err0 := l.svcCtx.Buyer.BuyerList(l.ctx, &bxbuyer.BuyerListReq{
		AppId:          req.AppId,
		BuyerName:      req.BuyerName,
		Province:       req.Province,
		City:           req.City,
		BuyerClass:     req.BuyerClass,
		IsCheckFollow:  req.IsCheckFollow,
		IsCheckReceive: req.IsCheckReceive,
		UserType:       req.UserType,
		UserId:         l.r.Header.Get("userId"),
		EntId:          req.EntId,
		EntUserId:      req.EntUserId,
		PageSize:       req.PageSize,
		PageNum:        req.PageNum,
		IsContact:      req.IsContact,
	})
	if err0 != nil {
		return &types.CommonResp{
			Err_code: -1,
			Err_msg:  "错误",
			Data:     nil,
		}, nil
	}
	return &types.CommonResp{
		Err_code: res.ErrCode,
		Err_msg:  res.ErrMsg,
		Data:     res.Data,
	}, nil
}
