<?php
declare(strict_types=1);

return [
    'key' => '20260408_003_add_bill_cancellation_columns',
    'description' => 'Adds optional cancellation metadata columns to bills for soft-void tracking.',
    'up' => static function (PDO $pdo): void {
        $columns = [
            'cancelled_at' => "ALTER TABLE bills ADD COLUMN cancelled_at DATETIME NULL AFTER out_date",
            'cancelled_by' => "ALTER TABLE bills ADD COLUMN cancelled_by INT NULL AFTER cancelled_at",
            'cancel_note' => "ALTER TABLE bills ADD COLUMN cancel_note TEXT NULL AFTER cancelled_by",
        ];

        $check = $pdo->prepare(
            'SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?'
        );

        foreach ($columns as $column => $sql) {
            $check->execute(['bills', $column]);
            if ((int)$check->fetchColumn() === 0) {
                $pdo->exec($sql);
            }
        }
    },
];
