<?php

declare(strict_types=1);

use App\Infrastructure\Db\Migrations\BaseMigration;

/**
 * Per-entity audit toggle. Defaults to enabled so existing reporters and
 * consumers keep emitting audit rows after the migration runs; admins can
 * silence individual chatty endpoints from the edit page.
 *
 * Effective rule: audit emits only when BOTH the global flag in
 * `app_settings` and the per-entity flag here are true. AND, not OR —
 * either side is sufficient to suppress.
 */
final class AddAuditEnabledToReportersConsumers extends BaseMigration
{
    public function up(): void
    {
        $this->table('reporters')
            ->addColumn('audit_enabled', 'boolean', ['null' => false, 'default' => true, 'after' => 'is_active'])
            ->update();

        $this->table('consumers')
            ->addColumn('audit_enabled', 'boolean', ['null' => false, 'default' => true, 'after' => 'is_active'])
            ->update();
    }

    public function down(): void
    {
        $this->table('reporters')->removeColumn('audit_enabled')->update();
        $this->table('consumers')->removeColumn('audit_enabled')->update();
    }
}
