package logic

import (
	"context"
	"errors"

	"juwan-backend/app/player/rpc/internal/svc"
	"juwan-backend/app/player/rpc/pb"

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

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

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

func (l *DelPlayersLogic) DelPlayers(in *pb.DelPlayersReq) (*pb.DelPlayersResp, error) {
	err := l.svcCtx.PlayerModelRW.Players.DeleteOneID(in.Id).Exec(l.ctx)
	if err != nil {
		logx.Errorf("delete player services failed, %s", err.Error())
		return nil, errors.New("delete failed")
	}

	return &pb.DelPlayersResp{}, nil
}
