package oauth_provider

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/oauthprovider"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
	"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
	"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"

	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
)

type DeleteOauthProviderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteOauthProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOauthProviderLogic {
	return &DeleteOauthProviderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteOauthProviderLogic) DeleteOauthProvider(in *core.IDsReq) (*core.BaseResp, error) {
	// 仅允许删除非系统内置数据
	_, err := l.svcCtx.DB.OauthProvider.Delete().
		Where(oauthprovider.IDIn(in.Ids...)).
		Where(oauthprovider.SystemEQ(false)).
		Exec(l.ctx)
	if err != nil {
		return nil, hander.HandleEntErr(err, in)
	}
	return &core.BaseResp{
		Code: code.StatusOK,
		Msg:  msg.DeleteSuccess,
	}, nil
}
