<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

/**
 * Customers table — each tenant can manage their own customer list for
 * quotes and invoices.
 */
final class CreateCustomers extends AbstractMigration
{
    public function change(): void
    {
        $this->table('customers', ['id' => 'customer_id', 'signed' => false])
            ->addColumn('tenant_id',       'integer', ['signed' => false])
            ->addColumn('name',            'string',  ['limit' => 200])
            ->addColumn('contact_person',  'string',  ['limit' => 200, 'null' => true])
            ->addColumn('email',           'string',  ['limit' => 200, 'null' => true])
            ->addColumn('phone',           'string',  ['limit' => 60,  'null' => true])
            ->addColumn('address',         'text',    ['null' => true])
            ->addColumn('tax_id',          'string',  ['limit' => 80,  'null' => true, 'comment' => 'VAT / TIN number'])
            ->addColumn('notes',           'text',    ['null' => true])
            ->addColumn('status',          'string',  ['limit' => 20, 'default' => 'active'])
            ->addColumn('created_at',      'datetime',['default' => 'CURRENT_TIMESTAMP'])
            ->addColumn('updated_at',      'datetime',['default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP'])
            ->addColumn('deleted_at',      'datetime',['null' => true])
            ->addIndex(['tenant_id', 'status'])
            ->addIndex(['tenant_id', 'name'])
            ->addForeignKey('tenant_id', 'tenants', 'tenant_id', ['delete' => 'RESTRICT', 'update' => 'CASCADE'])
            ->create();
    }
}