<?php

declare(strict_types=1);

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

final class CreateChannel 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('channel');
        if (!$exists) {
            $table = $this->table('channel', ['comment' => '渠道']);
            $table->addColumn('name', 'string', ['limit' => 120, 'null' => false, 'default' => '', 'comment' => '渠道名称'])
                ->addColumn('domain', 'string', ['limit' => 80, 'null' => false, 'default' => '', 'comment' => '渠道域名'])
                ->addColumn('lang', 'string', ['limit' => 20, 'null' => false, 'default' => '', 'comment' => '语言'])
                ->addColumn('currency', 'string', ['limit' => 10, 'null' => false, 'default' => '', 'comment' => '币别代码'])
                ->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'signed' => true, 'null' => false, 'default' => 0, 'comment' => '部门id'])
                ->addColumn('site_id', 'string', ['limit' => 100, 'signed' => true, 'null' => false, 'default' => 0, 'comment' => '渠道编号'])
                ->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '管理员id'])
                ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '状态(0:禁用,1:启用)'])
                ->addColumn('recharge_status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '平台充值(0:禁用,1:启用)'])
                ->addColumn('withdraw_status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '平台提现状态(0:禁用,1:启用)'])
                ->addColumn('web_login_status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => 'web登录状态(0:禁用,1:启用)'])
                ->addColumn('recharge_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => true, 'null' => false, 'default' => 0, 'comment' => '官方总充值金额'])
                ->addColumn('withdraw_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => true, 'null' => false, 'default' => 0, 'comment' => '官方总提现金额'])
                ->addColumn('wallet_action_status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '玩家钱包操作功能'])
                ->addColumn('created_at', 'timestamp', ['comment' => '创建时间'])
                ->addColumn('updated_at', 'timestamp', ['comment' => '更新时间'])
                ->addColumn('deleted_at', 'timestamp', ['comment' => '删除时间'])
                ->addIndex(['name'], ['unique' => true, 'name' => 'uni_name'])
                ->addIndex(['department_id'], ['name' => 'idx_department_id'])
                ->addIndex(['user_id'], ['name' => 'idx_user_id'])
                ->create();
        }
    }
}
