package oauthprovider_admin

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"

	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"

	"net/http"
)

type GetOauthProviderAdminLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewGetOauthProviderAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetOauthProviderAdminLogic {
	return &GetOauthProviderAdminLogic{
		r:      r,
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetOauthProviderAdminLogic) GetOauthProviderAdmin(req *types.OauthProviderReq) (resp *types.OauthProviderInfo, err error) {
	rpcResp, err := l.svcCtx.CoreRpc.GetOauthProvider(l.ctx, &core.OauthProviderReq{
		ID:       req.ID,
		Name:     req.Name,
		ClientId: req.ClientId,
		System:   req.System,
		Init:     req.Init,
	})
	if err != nil {
		return nil, err
	}
	resp = l.svcCtx.Convert.ConvertOAuthProvider(l.ctx, rpcResp)
	return
}
