package logic

import (
	"context"
	"jyBXSubscribe/rpc/model/service"

	"github.com/zeromicro/go-zero/core/logx"
	"jyBXSubscribe/rpc/internal/svc"
	"jyBXSubscribe/rpc/type/bxsubscribe"
)

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

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

// 用户邮箱保存
func (l *SetUserLogic) SetUser(in *bxsubscribe.SetUserInfoReq) (*bxsubscribe.StatusResp, error) {
	// todo: add your logic here and delete this line
	subService := &service.PushSetService{
		UserId:       in.UserId,
		PositionType: in.PositionType,
		EntUserId:    in.EntUserId,
		EntId:        in.EntId,
	}
	fool, msg := subService.SetUser(in.Mail)
	if fool {
		return &bxsubscribe.StatusResp{
			ErrorCode: 0,
		}, nil
	} else {
		return &bxsubscribe.StatusResp{
			ErrorCode: -1,
			ErrorMsg:  msg,
		}, nil
	}
}
