package base_organ_school

import (
	"context"

	"git.i2edu.net/i2/i2-bill-api/model"

	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/types"

	"git.i2edu.net/i2/go-zero/core/logx"
)

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

func NewGetErpSchPermLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetErpSchPermLogic {
	return GetErpSchPermLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetErpSchPermLogic) GetErpSchPerm() (*types.Response, error) {
	// todo: add your logic here and delete this line
	erpUser, err := model.GetAcquirePerm(l.svcCtx.GetUserIdByJwt(l.ctx), l.svcCtx.Transformer, l.svcCtx.DB, l.ctx)
	if err != nil {
		logx.Error(err.Error())
		return &types.Response{500, err.Error(), nil}, nil
	}
	if erpUser == nil || erpUser.UserId == "" {
		return &types.Response{200, "", nil}, nil
	}
	school, err := model.GetUserSchoolPerm(erpUser.UserId, l.svcCtx.Transformer, l.svcCtx.DB, l.ctx)
	if err != nil {
		logx.Error(err.Error())
		return &types.Response{500, err.Error(), nil}, nil
	}
	return &types.Response{200, "", school}, nil
}
