<?php

declare(strict_types=1);

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

final class CreatePlayerPlatformCash 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_platform_cash');
        if (!$exists) {
            $table = $this->table('player_platform_cash', ['comment' => '玩家钱包']);
            $table->addColumn('player_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '玩家id'])
                ->addColumn('platform_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '平台id'])
                ->addColumn('platform_name', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '平台名稱'])
                ->addColumn('money', 'decimal', ['precision' => 16, 'scale' => 2, 'null' => false, 'default' => 0, 'comment' => '點數'])
                ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '钱包状态'])
                ->addColumn('created_at', 'timestamp', ['comment' => '创建时间'])
                ->addColumn('updated_at', 'timestamp', ['comment' => '更新时间'])
                ->addIndex(['player_id'], ['name' => 'idx_player_id'])
                ->addIndex(['platform_id'], ['name' => 'idx_platform_id'])
                ->create();
        }
    }
}
