<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateDeviceTokensTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'msisdn' => [
                'type' => 'VARCHAR',
                'constraint' => '20',
                'null' => false,
            ],
            'fcm_token' => [
                'type' => 'VARCHAR',
                'constraint' => '512',
                'null' => false,
            ],
            'device_type' => [
                'type' => 'ENUM',
                'constraint' => ['android', 'ios', 'web'],
                'default' => 'android',
                'null' => false,
            ],
            'is_active' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'default' => 1,
                'null' => false,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('msisdn');
        $this->forge->addKey('fcm_token');
        $this->forge->createTable('device_tokens');
    }

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

