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 EmpowerLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

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

// 授权
func (l *EmpowerLogic) Empower(in *pb.EmpowerReq) (*pb.Resp, error) {
	resp := &pb.Resp{}
	status, err := Empower(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
}
