<?php

declare(strict_types=1);

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

final class CreateActivity 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
    {
        $table = $this->table('activity', ['comment' => '活动']);
        $table->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '渠道/部门id'])
            ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'signed' => false, 'null' => false, 'default' => 0, 'comment' => '狀態，0=停用, 1=啟用'])
            ->addColumn('sort', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'signed' => false, 'null' => false, 'default' => 0, 'comment' => '排序'])
            ->addColumn('link', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '连接地址'])
            ->addColumn('recharge_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '充值配置id'])
            ->addColumn('start_time', 'datetime', ['default' => null, 'comment' => '开始时间'])
            ->addColumn('end_time', 'datetime', ['default' => null, 'comment' => '结束时间'])
            ->addColumn('deleted_at', 'timestamp', ['comment' => '删除时间'])
            ->addColumn('created_at', 'timestamp', ['comment' => '创建时间'])
            ->addColumn('updated_at', 'timestamp', ['comment' => '更新时间'])
            ->addIndex(['department_id'], ['name' => 'idx_department_id'])
            ->create();
    }
}
