package main

import (
	"fmt"
	"os"

	"senlinai-agent/backend/internal/config"
	"senlinai-agent/backend/internal/models"
	"senlinai-agent/backend/internal/seed"
)

func main() {
	cfg := config.Load()
	if dsn := envOrDefault("DATABASE_DSN", envOrDefault("DATABASE_URL", "")); dsn != "" {
		cfg.DSN = dsn
	}
	if err := models.New(cfg.DSN); err != nil {
		panic(err)
	}
	result, err := seed.Demo(models.DBService, seed.DemoOptions{
		Email:       envOrDefault("SENLIN_SEED_EMAIL", "demo@senlin.ai"),
		DisplayName: envOrDefault("SENLIN_SEED_NAME", "演示用户"),
		Password:    envOrDefault("SENLIN_SEED_PASSWORD", "password123"),
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("seeded %s with %d projects\n", result.User.Email, len(result.Projects))
}

func envOrDefault(key string, fallback string) string {
	value := os.Getenv(key)
	if value == "" {
		return fallback
	}
	return value
}
