<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class TiendasTable extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('tiendas');
        $table
            ->addColumn('usuario_id', 'integer', ['null' => true, 'signed' => false])
            ->addColumn('zona_id', 'integer', ['null' => true, 'signed' => false])
            ->addColumn('nombre', 'string', ['limit' => 150])
            ->addColumn('direccion', 'string', ['limit' => 255])
            ->addColumn('lat', 'decimal', ['precision' => 10, 'scale' => 7])
            ->addColumn('lng', 'decimal', ['precision' => 10, 'scale' => 7])
            ->addColumn('telefono', 'string', ['limit' => 30, 'null' => true])
            ->addColumn('horario_apertura', 'time', ['null' => true])
            ->addColumn('horario_cierre', 'time', ['null' => true])
            ->addColumn('activo', 'boolean', ['default' => true])
            ->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP'])
            ->addColumn('updated_at', 'timestamp', ['null' => true, 'update' => 'CURRENT_TIMESTAMP'])
            ->addForeignKey('usuario_id', 'usuarios', 'id', ['delete' => 'SET_NULL', 'update' => 'CASCADE'])
            ->addForeignKey('zona_id', 'zonas', 'id', ['delete' => 'SET_NULL', 'update' => 'CASCADE'])
            ->create();
    }
}
