package main

import (
	"fmt"
	"log"

	"verification-platform-backend/internal/model"

	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
)

type User = model.User
type Application = model.Application
type Package = model.Package
type PackagePermission = model.PackagePermission
type UserPackage = model.UserPackage

func main() {
	dbPath := "verification_platform.db"

	db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
	if err != nil {
		log.Fatal("Failed to connect database:", err)
	}

	var users []User
	db.Find(&users)
	fmt.Println("=== 用户列表 ===")
	for _, u := range users {
		fmt.Printf("ID: %d, 用户名: %s, 当前套餐ID: %v\n", u.ID, u.Username, u.CurrentPackageID)
	}

	var packages []Package
	db.Find(&packages)
	fmt.Println("\n=== 套餐列表 ===")
	for _, p := range packages {
		fmt.Printf("ID: %d, 名称: %s\n", p.ID, p.Name)
	}

	var permissions []PackagePermission
	db.Find(&permissions)
	fmt.Println("\n=== 套餐权限 ===")
	for _, p := range permissions {
		fmt.Printf("套餐ID: %d, 最大应用数: %d\n", p.PackageID, p.MaxApplications)
	}

	var userPackages []UserPackage
	db.Find(&userPackages)
	fmt.Println("\n=== 用户套餐 ===")
	for _, up := range userPackages {
		fmt.Printf("用户ID: %d, 套餐ID: %d\n", up.UserID, up.PackageID)
	}

	var apps []Application
	db.Order("created_at ASC").Find(&apps)
	fmt.Println("\n=== 应用列表 ===")
	for i, a := range apps {
		fmt.Printf("索引: %d, ID: %d, 用户ID: %d, 名称: %s, 创建时间: %v\n", i, a.ID, a.UserID, a.Name, a.CreatedAt)
	}
}
