<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateRewarderAuthOtps extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'phone' => [
                'type' => 'VARCHAR',
                'constraint' => 32,
            ],
            'code' => [
                'type' => 'VARCHAR',
                'constraint' => 8,
            ],
            'purpose' => [
                'type' => 'VARCHAR',
                'constraint' => 16,
                'default' => 'login',
            ],
            'expires_at' => [
                'type' => 'DATETIME',
                'null' => false,
            ],
            'verified_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'attempts' => [
                'type' => 'INT',
                'constraint' => 11,
                'default' => 0,
            ],
            'status' => [
                'type' => 'VARCHAR',
                'constraint' => 16,
                'default' => 'pending',
            ],
            'ip_address' => [
                'type' => 'VARCHAR',
                'constraint' => 45,
                'null' => true,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => false,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey(['phone', 'status']);
        $this->forge->createTable('rewarder_auth_otps', true);
    }

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