package logic

import (
	"context"
	"jyBXSubscribe/rpc/bxsubscribe"

	"jyBXSubscribe/api/internal/svc"
	"jyBXSubscribe/api/internal/types"

	"app.yhyue.com/moapp/jybase/encrypt"
	"github.com/zeromicro/go-zero/core/logx"
)

type BidDistributorLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBidDistributorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BidDistributorLogic {
	return &BidDistributorLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BidDistributorLogic) BidDistributor(req *types.BidDistributor) (resp *types.CommonResp, err error) {
	infoids := []string{}
	for _, v := range req.Infoids {
		infoidArr := encrypt.DecodeArticleId2ByCheck(v)
		infoid := ""
		if len(infoidArr) > 0 {
			infoid = infoidArr[0]
		}
		if infoid == "" {
			continue
		}
		infoids = append(infoids, infoid)
	}
	res, err := l.svcCtx.Suscribe.BidDistributor(l.ctx, &bxsubscribe.BidDistributorReq{
		AppId:     req.AppId,
		EntId:     req.EntId,
		EntUserId: req.EntUserId,
		InfoIds:   infoids,
		Staffs:    req.Staffs,
	})
	return &types.CommonResp{
		Err_code: res.ErrorCode,
		Err_msg:  res.ErrorMsg,
		Data:     res.Status,
	}, err
}
