<?php
require_once __DIR__ . '/../app/includes/auth.php';

try {
    db()->exec("ALTER TABLE users ADD COLUMN mobile_number VARCHAR(60) DEFAULT NULL");
    echo "Added mobile_number to users.\n";
} catch (Exception $e) { echo $e->getMessage() . "\n"; }

try {
    db()->exec("ALTER TABLE users ADD COLUMN company_name VARCHAR(160) DEFAULT NULL");
    echo "Added company_name to users.\n";
} catch (Exception $e) { echo $e->getMessage() . "\n"; }

try {
    db()->exec("ALTER TABLE customers ADD COLUMN created_by INT(10) UNSIGNED DEFAULT NULL");
    db()->exec("ALTER TABLE customers ADD CONSTRAINT fk_customers_user FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL");
    echo "Added created_by to customers.\n";
} catch (Exception $e) { echo $e->getMessage() . "\n"; }

try {
    db()->exec("CREATE TABLE IF NOT EXISTS email_verifications (
        email VARCHAR(190) PRIMARY KEY,
        otp VARCHAR(10) NOT NULL,
        payload TEXT NOT NULL,
        expires_at DATETIME NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
    echo "Created email_verifications table.\n";
} catch (Exception $e) { echo $e->getMessage() . "\n"; }
