<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;

class OrdenTrabajoUsersTable extends Migration
{
    protected array $USER_COLUMNS = [
        'id' =>  [
            'type' => 'INT',
            'unsigned' => true,
            'auto_increment' => true,
        ],
        "orden_trabajo_id" => [
            "type" => "INT",
            "unsigned" => true,
        ],

        "user_created_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "user_update_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "inaplazable_revised_change_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],


        "ferro_disponible_hecho_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],

        "ferro_disponible_ok_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "ferro_entregado_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],

        "pendiente_ferro_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "ferro_en_cliente_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "ferro_ok_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],



        "interior_bn_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "interior_color_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "preparacion_interior_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "cubierta_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "plastificado_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "encuadernacion_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "corte_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "embalaje_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "envio_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "entrada_manipulado_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],


        "pre_formato_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],


        "pre_lomo_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],

        "pre_solapa_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],


        "pre_codbarras_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],

        "pre_imposicion_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "pre_imprimir_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
        "pre_imprimir_user_id" => [
            "type" => "INT",
            "unsigned" => true,
            "constraint" => 10,
            "null" => true,
        ],
    ];
    
    public function up()
    {
        $this->forge->dropTable('orden_trabajo_users',true);
        $currenttime = new RawSql("CURRENT_TIMESTAMP");
        $this->forge->addField($this->USER_COLUMNS);
        $this->forge->addField([
            "created_at" => [
                "type" => "TIMESTAMP",
                "default" => $currenttime,
            ],
            "updated_at" => [
                "type" => "TIMESTAMP",
                "null" => true,
            ],
            "deleted_at" => [
                "type" => "TIMESTAMP",
                "null" => true,
            ],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addForeignKey("orden_trabajo_id", "ordenes_trabajo","id");
        $this->forge->createTable("orden_trabajo_users");
    }

    public function down()
    {
        $this->forge->dropTable('orden_trabajo_users');
    }
}
