//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//

package providers

import (
	"github.com/veypi/vbase/cfg"
	"github.com/veypi/vbase/models"
	"github.com/veypi/vigo"
)

// GetRequest 获取详情请求
type GetRequest struct {
	Code string `src:"path@code" desc:"提供商代码"`
}

// get 获取 OAuth 提供商详情
func get(x *vigo.X, req *GetRequest) (*models.OAuthProvider, error) {
	var provider models.OAuthProvider
	if err := cfg.DB().Where("code = ?", req.Code).First(&provider).Error; err != nil {
		return nil, vigo.ErrNotFound.WithError(err)
	}

	// 敏感字段置空
	provider.ClientSecret = ""

	return &provider, nil
}
