package logic

import (
	"context"
	"fmt"
	"strings"

	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"

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

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

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

// 先把有权限的人清空，再把权益授权给新的人
func (l *ReEmpowerLogic) ReEmpower(in *pb.EmpowerReq) (*pb.Resp, error) {
	resp := &pb.Resp{}
	status, err := ReEmpower(in.Appid, strings.Split(in.FunctionCode, ","), in.EntId, in.EntUserId)
	if err != nil {
		l.Error(fmt.Sprintf("%+v", in), err)
	}
	resp.Status = status
	return resp, nil
}
