<?php

declare(strict_types=1);

use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Migration\AbstractMigration;

final class CreatePlayerRegisterRecord extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $exists = $this->hasTable('player_register_record');
        if (!$exists) {
            $table = $this->table('player_register_record', ['comment' => '玩家注册记录']);
            $table->addColumn('player_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '玩家id'])
                ->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '部门/渠道id'])
                ->addColumn('register_domain', 'string', ['limit' => 125, 'null' => false, 'default' => '', 'comment' => '登錄域名'])
                ->addColumn('ip', 'string', ['limit' => 125, 'null' => false, 'default' => '', 'comment' => 'ip'])
                ->addColumn('country_name', 'string', ['limit' => 125, 'null' => false, 'default' => '', 'comment' => '國家名稱'])
                ->addColumn('city_name', 'string', ['limit' => 125, 'null' => false, 'default' => '', 'comment' => '地區名稱'])
                ->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'signed' => true, 'null' => false, 'default' => 0, 'comment' => '類型 0未讀 1已讀'])
                ->addColumn('remark', 'string', ['limit' => 125, 'null' => false, 'default' => '', 'comment' => '備註'])
                ->addColumn('device', 'string', ['limit' => 125, 'null' => false, 'default' => '', 'comment' => '使用設備'])
                ->addColumn('created_at', 'timestamp', ['comment' => '创建时间'])
                ->addColumn('updated_at', 'timestamp', ['comment' => '更新时间'])
                ->addIndex(['player_id'], ['name' => 'idx_player_id'])
                ->addIndex(['department_id'], ['name' => 'idx_department_id'])
                ->create();
        }
    }
}
