package main

import (
	"flag"
	"fmt"
	"os"

	"osaet/backend/internal/postimport"
)

func main() {
	fs := flag.NewFlagSet("import-articles", flag.ExitOnError)
	file := fs.String("file", "articles.csv", "CSV file path")
	overwrite := fs.Bool("overwrite", false, "overwrite existing markdown files")
	postsDir := fs.String("posts-dir", "content/posts", "posts output directory relative to project root")
	if err := fs.Parse(os.Args[1:]); err != nil {
		fmt.Fprintln(os.Stderr, "error:", err)
		os.Exit(1)
	}

	result, err := postimport.Import(postimport.Options{
		CSVPath:    *file,
		PostsDir:   *postsDir,
		Overwrite:  *overwrite,
		WorkingDir: "",
	})
	if err != nil {
		fmt.Fprintln(os.Stderr, "error:", err)
		os.Exit(1)
	}

	fmt.Printf("imported %d post(s), skipped %d existing file(s), skipped %d non-post row(s)\n", result.Imported, result.SkippedExisting, result.SkippedNonPost)
}
