<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateInterviews extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id'                   => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'job_application_id'   => ['type' => 'BIGINT', 'unsigned' => true],
            'scheduled_by_user_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'scheduled_at'         => ['type' => 'DATETIME'],
            'duration_minutes'     => ['type' => 'SMALLINT', 'unsigned' => true, 'default' => 30],
            'mode'                 => ['type' => 'ENUM', 'constraint' => ['zoom', 'google_meet', 'onsite', 'phone'], 'default' => 'zoom'],
            'meeting_link'         => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'location'             => ['type' => 'TEXT', 'null' => true],
            'status'               => ['type' => 'ENUM', 'constraint' => ['scheduled', 'rescheduled', 'cancelled', 'completed'], 'default' => 'scheduled'],
            'feedback'             => ['type' => 'TEXT', 'null' => true],
            'feedback_rating'      => ['type' => 'TINYINT', 'unsigned' => true, 'null' => true],
            'created_at'           => ['type' => 'TIMESTAMP', 'null' => true],
            'updated_at'           => ['type' => 'TIMESTAMP', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey('scheduled_at');
        $this->forge->addForeignKey('job_application_id', 'job_applications', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('scheduled_by_user_id', 'users', 'id', false, 'RESTRICT');
        $this->forge->createTable('interviews', true, ['ENGINE' => 'InnoDB']);
    }

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