<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePdfTemplatesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'original_name' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
            ],
            'stored_path' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
            ],
            'page_count' => [
                'type'       => 'INT',
                'constraint' => 5,
                'unsigned'   => true,
                'default'    => 1,
            ],
            'page_width_mm' => [
                'type'       => 'DECIMAL',
                'constraint' => '7,2',
                'default'    => 210.00,
            ],
            'page_height_mm' => [
                'type'       => 'DECIMAL',
                'constraint' => '7,2',
                'default'    => 297.00,
            ],
            'zones' => [
                'type' => 'LONGTEXT',
                'null' => true,
            ],
            'is_active' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 0,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('is_active');
        $this->forge->createTable('pdf_templates');
    }

    public function down()
    {
        $this->forge->dropTable('pdf_templates', true);
    }
}
