package oauth

import (
	"runtime"
	"strings"
)

// EZConfIntegration provides integration with ezconf for automatic configuration
type EZConfIntegration struct {
	configFunc func() (any, error)
	name       string
}

// PackagePath returns the path to the config package for source parsing
func (e EZConfIntegration) PackagePath() string {
	_, filename, _, _ := runtime.Caller(0)
	// Return directory of this file
	return filename[:len(filename)-len("/ezconf.go")]
}

// ConfigFunc returns the ConfigFromEnv function for ezconf
func (e EZConfIntegration) ConfigFunc() func() (any, error) {
	return func() (any, error) {
		return e.configFunc()
	}
}

// Name returns the name to use when registering with ezconf
func (e EZConfIntegration) Name() string {
	return strings.ToLower(e.name)
}

// GroupName returns the display name for grouping environment variables
func (e EZConfIntegration) GroupName() string {
	return e.name
}

// NewEZConfIntegration creates a new EZConf integration helper
func NewEZConfIntegration() EZConfIntegration {
	return EZConfIntegration{name: "OAuth", configFunc: ConfigFromEnv}
}
