package logic

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

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

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

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

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

func (l *GetStaffSubscribeListLogic) GetStaffSubscribeList(req *types.GetStaffSubscribeListReq) (resp *types.StaffSubscribeCommonResp, err error) {
	res, err := l.svcCtx.Suscribe.GetStaffSubscribeList(l.ctx, &bxsubscribe.StaffSubscribeReq{
		AppId:     req.AppId,
		EntId:     req.EntId,
		EntUserId: req.EntUserId,
		Query:     req.Search,
		EStatus:   req.EStatus,
		PStatus:   req.PStatus,
		PageNum:   req.PageNum,
		PageSize:  req.PageSize,
	})
	if err != nil {
		return nil, err
	}
	if res.ErrCode != 0 {
		return &types.StaffSubscribeCommonResp{
			Err_code: res.ErrCode,
			Err_msg:  res.ErrMsg,
			Data:     nil,
		}, nil
	}
	return &types.StaffSubscribeCommonResp{
		Err_code: res.ErrCode,
		Err_msg:  res.ErrMsg,
		Data: map[string]interface{}{
			"total": res.Total,
			"list":  res.Items,
		},
	}, nil
}
