package config

import (
	"os"

	"sigs.k8s.io/yaml"
)

type CronInspectConfig struct {
	// Schedule is the cron schedule.
	//
	// Ref: https://pkg.go.dev/github.com/robfig/cron#hdr-Usage
	Schedule string `json:"schedule"`

	// List contains configurations for listing resources.
	List ListConfig `json:"list"`

	// Engine contains configurations for engines.
	Engine EngineConfig `json:"engine"`
}

type DaemonConfig struct {
	// Environment is the environment, contains: dev, staging, prod.
	Environment string `json:"env"`
	// InfraKubeConfig is the file path of kubeconfig to access the infra apiserver.
	InfraKubeConfig string `json:"infraKubeConfig"`
	// GardenerKubeConfig is the file path of kubeconfig to access the gardener apiserver.
	GardenerKubeConfig string `json:"gardenerKubeConfig"`

	// Notify contains configurations for notification.
	Notify NotifyConfig `json:"notify"`

	// Infra contains configurations for inspecting infra clusters.
	Infra *CronInspectConfig `json:"infra"`
	// Gardener contains configurations for inspecting gardener clusters.
	Gardener *CronInspectConfig `json:"gardener"`
	// Dataplane contains configurations for inspecting dataplane clusters.
	Dataplane *CronInspectConfig `json:"dataplane"`
}

func LoadDaemonConfig(path string) (*DaemonConfig, error) {
	data, err := os.ReadFile(path)
	if err != nil {
		return nil, err
	}
	config := &DaemonConfig{}
	err = yaml.Unmarshal(data, config)
	if err != nil {
		return nil, err
	}

	return config, nil
}
