package config

import (
	"encoding/json"
	"fmt"
	"os"
)

type Config struct {
	AdminToken string `json:"adminToken"`
	AuthAPIURL string `json:"authApiUrl"`
}

func Load(path string) (*Config, error) {
	data, err := os.ReadFile(path)
	if err != nil {
		return nil, fmt.Errorf("read config: %w", err)
	}
	var cfg Config
	if err := json.Unmarshal(data, &cfg); err != nil {
		return nil, fmt.Errorf("parse config: %w", err)
	}
	if cfg.AdminToken == "" {
		cfg.AdminToken = "shumengya520"
	}
	return &cfg, nil
}
