package auth

import (
    "os"
    "database/sql"
    "golang.org/x/crypto/bcrypt"
    _ "github.com/lib/pq"
)

// CreateAdminUser erstellt einen Standard-Admin in der DB
func CreateAdminUser(db *sql.DB) error {
    password := os.Getenv("ADMIN_PASSWORD")
    hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
    if err != nil {
        return err
    }

    // In DB speichern
    _, err = db.Exec("INSERT INTO users (username, password_hash) VALUES ($1, $2) ON CONFLICT (username) DO NOTHING", "admin", string(hash))
    return err
}
