<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateSignaturesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'signable_type' => ['type' => "ENUM('inspection','report')"],
            'signable_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'role' => ['type' => "ENUM('inspector','cliente')"],
            'name' => ['type' => 'VARCHAR', 'constraint' => 200, 'null' => true],
            'png_path' => ['type' => 'VARCHAR', 'constraint' => 255],
            'signed_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey(['signable_type', 'signable_id']);
        $this->forge->createTable('signatures');
    }

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