<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateNotificationSettingsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'company_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'renewal_days_before' => ['type' => 'VARCHAR', 'constraint' => 255, 'default' => '7,3,1'],
            'invoice_due_days_before' => ['type' => 'VARCHAR', 'constraint' => 255, 'default' => '7,3,1'],
            'admin_notification_email' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('company_id', 'companies', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('notification_settings');
    }

    public function down()
    {
        $this->forge->dropTable('notification_settings');
    }
}
