package main

import (
	"fmt"
	"log"

	"verification-platform-backend/internal/database"
	"verification-platform-backend/internal/model"
)

func main() {
	database.Init()
	db := database.DB

	packageTranslations := map[string]struct {
		NameEn        string
		DescriptionEn string
	}{
		"免费版": {
			NameEn:        "Free",
			DescriptionEn: "Basic features for individual admins",
		},
		"公益版": {
			NameEn:        "Community",
			DescriptionEn: "Free for individual admins",
		},
		"专业版": {
			NameEn:        "Professional",
			DescriptionEn: "Advanced features for professional admins",
		},
		"企业版": {
			NameEn:        "Enterprise",
			DescriptionEn: "Full features for enterprise teams",
		},
		"基础版": {
			NameEn:        "Basic",
			DescriptionEn: "Essential features for small projects",
		},
		"高级版": {
			NameEn:        "Premium",
			DescriptionEn: "Premium features for growing businesses",
		},
		"旗舰版": {
			NameEn:        "Flagship",
			DescriptionEn: "Top-tier features for large organizations",
		},
		"开发者版": {
			NameEn:        "Developer",
			DescriptionEn: "Perfect for individual admins",
		},
		"团队版": {
			NameEn:        "Team",
			DescriptionEn: "Collaborative features for teams",
		},
		"个人版": {
			NameEn:        "Personal",
			DescriptionEn: "Personal use with essential features",
		},
		"标准版": {
			NameEn:        "Standard",
			DescriptionEn: "Standard features for regular users",
		},
	}

	var packages []model.Package
	if err := db.Find(&packages).Error; err != nil {
		log.Fatal("Failed to get packages:", err)
	}

	for _, pkg := range packages {
		if trans, ok := packageTranslations[pkg.Name]; ok {
			pkg.NameEn = trans.NameEn
			pkg.DescriptionEn = trans.DescriptionEn
			if err := db.Save(&pkg).Error; err != nil {
				log.Printf("Failed to update package %d: %v", pkg.ID, err)
			} else {
				fmt.Printf("Translated package: %s -> %s\n", pkg.Name, pkg.NameEn)
			}
		} else {
			pkg.NameEn = pkg.Name
			if pkg.Description != "" {
				pkg.DescriptionEn = pkg.Description
			}
			if err := db.Save(&pkg).Error; err != nil {
				log.Printf("Failed to update package %d: %v", pkg.ID, err)
			} else {
				fmt.Printf("Copied package: %s (no translation found)\n", pkg.Name)
			}
		}
	}

	fmt.Println("\nPackage translation completed!")
}
