<?php
// PromoCreative LED Mapper - Configuração Geral

date_default_timezone_set('America/Recife');

define('DB_HOST', 'localhost');
define('DB_NAME', 'prom5576_painelled');
define('DB_USER', 'prom5576_led');
define('DB_PASS', '35331345d@nilo');

define('APP_NAME', 'PromoCreative LED Mapper');
define('APP_VERSION', '1.0.0');

// Chave secreta da API
define('API_SECRET', 'troque-essa-chave-secreta-aqui-2026');

try {
    $pdo = new PDO(
        "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4",
        DB_USER,
        DB_PASS,
        [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        ]
    );
} catch (PDOException $e) {
    http_response_code(500);
    die(json_encode([
        'success' => false,
        'message' => 'Erro ao conectar ao banco de dados.'
    ]));
}

function jsonResponse($success, $message, $extra = [])
{
    header('Content-Type: application/json; charset=utf-8');

    echo json_encode(array_merge([
        'success' => $success,
        'message' => $message
    ], $extra), JSON_UNESCAPED_UNICODE);

    exit;
}

function gerarChaveLicenca()
{
    return 'PCLM-' . date('Y') . '-' .
        strtoupper(substr(bin2hex(random_bytes(2)), 0, 4)) . '-' .
        strtoupper(substr(bin2hex(random_bytes(2)), 0, 4)) . '-' .
        strtoupper(substr(bin2hex(random_bytes(2)), 0, 4));
}