<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateSpinRewardsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'msisdn' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => true,
            ],
            'points' => [
                'type' => 'INT',
                'constraint' => 11,
                'default' => 0,
            ],
            'spin_date' => [
                'type' => 'DATE',
                'null' => false,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => false,
            ],
            'claimed_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('msisdn');
        $this->forge->addKey('spin_date');
        $this->forge->addUniqueKey(['msisdn', 'spin_date']);
        $this->forge->createTable('spin_rewards', true);
    }

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