<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateOrganizationPrivacySettingsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'organization_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'visibility_mode' => ['type' => 'VARCHAR', 'constraint' => 20, 'default' => 'standard'],
            'show_public_reference' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'show_organization_name' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'show_facility_name' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
            'show_energy' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'show_period' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'show_blockchain' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
            'show_hashes' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'show_rule_name' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey('organization_id');
        $this->forge->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('organization_privacy_settings', true);
    }

    public function down()
    {
        $this->forge->dropTable('organization_privacy_settings', true);
    }
}
