<?php

use Phinx\Db\Adapter\MysqlAdapter;

class CreateVenta extends Phinx\Migration\AbstractMigration
{
	public function change(): void
	{
		$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
		$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
		$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");

		$this->table('venta')
			->addColumn('propietario', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
			->addColumn('propiedad', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
			->addColumn('pie', 'integer', ['length' => 10, 'default' => 0, 'signed' => false])
			->addColumn('bono_pie', 'integer', ['length' => 11, 'default' => 0])
			->addColumn('credito', 'integer', ['length' => 10, 'default' => 0, 'signed' => false])
			->addColumn('escritura', 'integer', ['length' => 11, 'default' => 0])
			->addColumn('subsidio', 'integer', ['length' => 11, 'default' => 0, 'signed' => false])
			->addColumn('escriturado', 'date', ['default' => null, 'null' => true])
			->addColumn('entrega', 'integer', ['length' => 11, 'default' => 0])
			->addColumn('entregado', 'date', ['default' => null, 'null' => true])
			->addColumn('fecha', 'date', ['null' => false])
			->addColumn('valor_uf', 'double', ['null' => false, 'signed' => false])
			->addColumn('estado', 'integer', ['length' => 11, 'default' => 1, 'null' => false])
			->addColumn('fecha_ingreso', 'date', ['default' => null, 'null' => true])
			->addColumn('avalchile', 'boolean', ['length' => 1, 'default' => 0])
			->addColumn('agente', 'integer', ['length' => 10, 'default' => 0, 'signed' => false])
			->addColumn('uf', 'double', ['default' => null, 'null' => true])
			->addColumn('relacionado', 'integer', ['length' => 1, 'default' => 0])
			->addColumn('promocion', 'integer', ['length' => 10, 'default' => 0, 'signed' => false])
			->addColumn('resciliacion', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
			->addColumn('devolucion', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
			->addForeignKey('propiedad', 'propiedad', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
			->addForeignKey('propietario', 'propietario', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
			->create();
		$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
	}
}
