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 RelatesInformationLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

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

func (l *RelatesInformationLogic) RelatesInformation(req *types.RelatesInformationReq) (resp *types.CommonResp, err error) {
	res, err0 := l.svcCtx.Buyer.RelatesInfo(l.ctx, &bxbuyer.RelatesInformationReq{
		Area:         req.Area,
		City:         req.City,
		BiddingCount: int64(req.BiddingCount),
		BuyerCount:   int64(req.BuyerCount),
		Buyer:        req.Buyer,
		PositionId:   req.PositionId,
		PositionType: req.PositionType,
		Phone:        req.Phone,
	})
	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
}
