<?php

declare(strict_types=1);

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

final class CreateSystemSetting 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('system_setting');
        if (!$exists) {
            $table = $this->table('system_setting', ['comment' => '系统设计']);
            $table->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '部门/渠道id'])
                ->addColumn('feature', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '功能名稱'])
                ->addColumn('num', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'default' => null, 'comment' => '數量'])
                ->addColumn('content', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR, 'comment' => '內容'])
                ->addColumn('date_start', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '开始时间'])
                ->addColumn('date_end', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '结束时间'])
                ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 1, 'comment' => '1啟用 0停用'])
                ->addColumn('created_at', 'timestamp', ['comment' => '创建时间'])
                ->addColumn('updated_at', 'timestamp', ['comment' => '更新时间'])
                ->create();
        }
    }
}
