package main

import (
	"context"
	"log"
	"photum-backend/internal/config"

	"github.com/jackc/pgx/v5/pgxpool"
)

func main() {
	cfg := config.LoadConfig()
	log.Printf("Connecting to DB: %s", cfg.DBDsn)

	pool, err := pgxpool.New(context.Background(), cfg.DBDsn)
	if err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}
	defer pool.Close()

	queries := []string{
		"ALTER TABLE cadastro_profissionais ADD COLUMN IF NOT EXISTS conta VARCHAR(20);",
		"UPDATE cadastro_fot SET regiao = 'SP' WHERE regiao IS NULL OR regiao = '' OR regiao = '  ';",
		"ALTER TABLE cadastro_fot ALTER COLUMN regiao SET DEFAULT 'SP';",
	}

	for _, q := range queries {
		log.Printf("Executing: %s", q)
		if _, err := pool.Exec(context.Background(), q); err != nil {
			log.Printf("Error (might be expected if exists): %v", err)
		} else {
			log.Println("Success.")
		}
	}
	log.Println("DB Fix Complete")
}
