-- One-off migration: adds the invoice_requests table, used to track a
-- parent's confirmation that they intend to pay when their child's balance
-- runs low. A row is created by cron/send_payment_reminders.php when a
-- student's balance drops below the low-balance threshold; the parent then
-- approves or declines it from their dashboard. Approval does NOT insert
-- into `payments` (that table is summed live into every balance
-- calculation, so a "pending" payment row would falsely inflate the
-- balance) -- staff record the real payment through the existing
-- "Добавить оплату" flow on /students.php, which marks the request
-- 'fulfilled'. Run once against the app database:
--
--   mysql -h <host> -u <user> -p <database> < scripts/create_invoice_requests_table.sql
--
-- (or paste the statement below into phpMyAdmin / Adminer / your MySQL
-- client of choice). No existing tables are modified.

CREATE TABLE IF NOT EXISTS invoice_requests (
    id                     INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    student_id             INT NOT NULL,
    balance_at_trigger     DECIMAL(10,2) NOT NULL,
    status                 ENUM('pending', 'approved', 'declined', 'fulfilled') NOT NULL DEFAULT 'pending',
    created_at             DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at             DATETIME NULL,
    INDEX idx_invoice_requests_student_status (student_id, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
