<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddSecuritySettingsToCompanySettings extends Migration
{
    public function up(): void
    {
        $fields = [
            'tpin_enabled' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 1,
                'after'      => 'fiscal_year_start_month',
            ],
            'tpin_required_by_default' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 0,
                'after'      => 'tpin_enabled',
            ],
            'tpin_max_failed_attempts' => [
                'type'       => 'TINYINT',
                'unsigned'   => true,
                'default'    => 5,
                'after'      => 'tpin_required_by_default',
            ],
            'tpin_lockout_minutes' => [
                'type'       => 'SMALLINT',
                'unsigned'   => true,
                'default'    => 15,
                'after'      => 'tpin_max_failed_attempts',
            ],
        ];

        $this->forge->addColumn('company_settings', $fields);
    }

    public function down(): void
    {
        $this->forge->dropColumn('company_settings', [
            'tpin_enabled',
            'tpin_required_by_default',
            'tpin_max_failed_attempts',
            'tpin_lockout_minutes',
        ]);
    }
}
