package cli

import "strings"

const (
	defaultPostsDir    = "content/posts"
	defaultAssetsDir   = "content/assets"
	defaultTrashDir    = "content/.trash/posts"
	defaultAstroDir    = "frontend/site"
	defaultBuildOutDir = "dist/site"
	defaultSQLitePath  = ".osaet/osaet.db"
)

type postFile struct {
	Path        string
	Frontmatter postFrontmatter
	Body        string
}

type postFrontmatter struct {
	ID          string   `yaml:"id"`
	Slug        string   `yaml:"slug"`
	Title       string   `yaml:"title"`
	Summary     string   `yaml:"summary"`
	Status      string   `yaml:"status"`
	Tags        []string `yaml:"tags"`
	Cover       string   `yaml:"cover"`
	Version     int      `yaml:"version"`
	SlugSource  string   `yaml:"slug_source"`
	SlugLocked  bool     `yaml:"slug_locked"`
	PublishedAt *string  `yaml:"published_at"`
	CreatedAt   string   `yaml:"created_at"`
	UpdatedAt   string   `yaml:"updated_at"`
}

type localConfig struct {
	DeepSeek struct {
		APIKey    string `yaml:"api_key"`
		APIKeyEnv string `yaml:"api_key_env"`
		BaseURL   string `yaml:"base_url"`
		Model     string `yaml:"model"`
	} `yaml:"deepseek"`
}

type siteConfigFile struct {
	Meta struct {
		ConfigVersion int    `yaml:"config_version" json:"config_version"`
		UpdatedAt     string `yaml:"updated_at" json:"updated_at"`
		UpdatedBy     string `yaml:"updated_by" json:"updated_by"`
	} `yaml:"meta" json:"meta"`
	Site struct {
		Title       string `yaml:"title" json:"title"`
		Description string `yaml:"description" json:"description"`
		BaseURL     string `yaml:"base_url" json:"base_url"`
		Language    string `yaml:"language" json:"language"`
		Timezone    string `yaml:"timezone" json:"timezone"`
	} `yaml:"site" json:"site"`
	Content struct {
		PostsDir  string `yaml:"posts_dir" json:"posts_dir"`
		AssetsDir string `yaml:"assets_dir" json:"assets_dir"`
	} `yaml:"content" json:"content"`
	Build struct {
		AstroProject string `yaml:"astro_project" json:"astro_project"`
		OutputDir    string `yaml:"output_dir" json:"output_dir"`
	} `yaml:"build" json:"build"`
}

type stringListFlag struct {
	values []string
}

func (f *stringListFlag) String() string {
	return strings.Join(f.values, ",")
}

func (f *stringListFlag) Set(value string) error {
	value = strings.TrimSpace(value)
	if value == "" {
		return nil
	}
	f.values = append(f.values, value)
	return nil
}

func (f *stringListFlag) Values() []string {
	return append([]string(nil), f.values...)
}
