<?php

declare(strict_types=1);

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

final class CreatePlayerWithdrawRecord 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_withdraw_record');
        if (!$exists) {
            $table = $this->table('player_withdraw_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('talk_user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'default' => null, 'comment' => '来聊聊账号id'])
                ->addColumn('player_tag', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '玩家標籤'])
                ->addColumn('tradeno', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '單號'])
                ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '狀態,  1=提现中(待审核), 2=成功, 3=失败 , 4=待打款, 5=不通过, 6=玩家取消, 7=系统取消'])
                ->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '1=来聊聊 , 2=银行卡'])
                ->addColumn('player_name', 'string', ['limit' => 20, 'null' => false, 'default' => null, 'comment' => '玩家姓名'])
                ->addColumn('player_phone', 'string', ['limit' => 20, 'null' => false, 'default' => null, 'comment' => '玩家手機號碼'])
                ->addColumn('point', 'decimal', ['precision' => 14, 'scale' => 2, 'null' => false, 'default' => 0, 'comment' => '游戏点数'])
                ->addColumn('money', 'decimal', ['precision' => 14, 'scale' => 2, 'null' => false, 'default' => 0, 'comment' => '出款金額'])
                ->addColumn('inmoney', 'decimal', ['precision' => 14, 'scale' => 2, 'null' => false, 'default' => 0, 'comment' => '實際出款金額'])
                ->addColumn('fee', 'decimal', ['precision' => 14, 'scale' => 2, 'null' => false, 'default' => 0, 'comment' => '手續費'])
                ->addColumn('bank_name', 'string', ['limit' => 100, 'null' => false, 'default' => null, 'comment' => '银行名称'])
                ->addColumn('account', 'string', ['limit' => 100, 'null' => false, 'default' => null, 'comment' => '银行账号'])
                ->addColumn('account_name', 'string', ['limit' => 100, 'null' => false, 'default' => null, 'comment' => '账户所属人'])
                ->addColumn('currency', 'string', ['limit' => 100, 'null' => false, 'default' => null, 'comment' => '幣種'])
                ->addColumn('remark', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '備註'])
                ->addColumn('reject_reason', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '拒绝原因'])
                ->addColumn('finish_time', 'datetime', ['comment' => '出款成功時間'])
                ->addColumn('cancel_time', 'datetime', ['comment' => '取消時間'])
                ->addColumn('created_at', 'timestamp', ['comment' => '创建时间'])
                ->addColumn('updated_at', 'timestamp', ['comment' => '更新时间'])
                ->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'signed' => true, 'null' => false, 'default' => 0, 'comment' => '管理员id'])
                ->addColumn('user_name', 'string', ['limit' => 50, 'null' => false, 'default' => '', 'comment' => '管理员'])
                ->addColumn('certificate', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '打款凭证'])
                ->addIndex(['tradeno'], ['name' => 'uni_tradeno', 'unique' => true])
                ->addIndex(['status'], ['name' => 'idx_status'])
                ->addIndex(['player_name'], ['name' => 'idx_player_name'])
                ->addIndex(['player_id'], ['name' => 'idx_player_id'])
                ->addIndex(['talk_user_id'], ['name' => 'idx_talk_user_id'])
                ->addIndex(['department_id'], ['name' => 'idx_department_id'])
                ->create();
        }
    }
}
