package main

import (
	"fmt"
	"log"

	"bindbox-game/configs"
	"bindbox-game/internal/repository/mysql"
	"bindbox-game/internal/repository/mysql/model"

	"gorm.io/gorm"
)

func main() {
	// Initialize Config
	configs.Init()

	// Initialize Database
	dbRepo, err := mysql.New()
	if err != nil {
		log.Fatalf("Failed to init db: %v", err)
	}
	db := dbRepo.GetDbW()

	// Add column
	msg := addColumn(db)
	fmt.Println(msg)
}

func addColumn(db *gorm.DB) string {
	// Check if column exists
	if db.Migrator().HasColumn(&model.LivestreamPrizes{}, "CostPrice") {
		return "Column 'cost_price' already exists in 'livestream_prizes'"
	}

	// Add column
	err := db.Migrator().AddColumn(&model.LivestreamPrizes{}, "CostPrice")
	if err != nil {
		log.Fatalf("Failed to add column: %v", err)
	}

	return "Successfully added column 'cost_price' to 'livestream_prizes'"
}
