package main

import (
	"database/sql"
	"fmt"

	_ "github.com/lib/pq"
	"golang.org/x/crypto/bcrypt"
)

func main() {
	db, err := sql.Open("postgres", "postgres://yuki:xl1zfmr6e9bb@db-60059.dc-sp-1.absamcloud.com:26868/gohorsejobs_dev?sslmode=require")
	if err != nil {
		fmt.Println("❌ Connection error:", err)
		return
	}
	defer db.Close()

	// USE THE PEPPER FROM THE DEPLOYED BACKEND .env
	password := "Admin@2025!"
	pepper := "some-random-string-for-password-hashing" // FROM DEPLOYED .env
	passwordWithPepper := password + pepper

	newHash, err := bcrypt.GenerateFromPassword([]byte(passwordWithPepper), bcrypt.DefaultCost)
	if err != nil {
		fmt.Println("❌ Hash generation error:", err)
		return
	}

	fmt.Println("🔐 Generated new hash with CORRECT pepper:")
	fmt.Println("   Password:", password)
	fmt.Println("   Pepper:", pepper)
	fmt.Println("   Hash:", string(newHash))

	result, err := db.Exec("UPDATE users SET password_hash = $1, status = 'active' WHERE identifier = 'superadmin'", string(newHash))
	if err != nil {
		fmt.Println("❌ Update error:", err)
		return
	}

	rows, _ := result.RowsAffected()
	fmt.Printf("\n✅ SuperAdmin updated! Rows affected: %d\n", rows)
	fmt.Println("\n🔄 Tente logar novamente com superadmin / Admin@2025!")
}
