<?php

declare(strict_types=1);

use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Migrations\Migration;

class CreateBarangayBlottersTable extends Migration
{
    public function up(): void
    {
        Schema::create('barangay_blotters', function (Blueprint $table) {
            $table->id();
            $table->string('hashkey')->unique()->nullable();
            $table->string('blotter_no')->unique()->nullable();
            $table->unsignedBigInteger('complainant_user_id')->nullable()->index();
            $table->string('complainant_name');
            $table->string('complainant_contact')->nullable();
            $table->unsignedBigInteger('respondent_user_id')->nullable()->index();
            $table->string('respondent_name')->nullable();
            $table->string('respondent_contact')->nullable();
            $table->enum('incident_type', ['AMICABLE', 'UNLAWFUL', 'MINOR', 'OTHER'])->default('AMICABLE');
            $table->date('incident_date')->nullable();
            $table->string('incident_location')->nullable();
            $table->text('narrative')->nullable();
            $table->enum('status', ['FILED', 'FOR_HEARING', 'SETTLED', 'RESOLVED', 'DISMISSED', 'ENDORSED'])->default('FILED');
            $table->timestamp('complaint_date')->nullable();
            $table->unsignedBigInteger('filed_by')->nullable();
            $table->unsignedBigInteger('assigned_officer_id')->nullable()->index();
            $table->text('resolution')->nullable();
            $table->string('settlement_type')->nullable();
            $table->string('endorsed_to')->nullable();
            $table->boolean('is_active')->default(true);
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('barangay_blotter_hearings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('blotter_id')->index();
            $table->timestamp('hearing_date')->nullable();
            $table->enum('status', ['SCHEDULED', 'HELD', 'POSTPONED'])->default('SCHEDULED');
            $table->unsignedBigInteger('officer_id')->nullable();
            $table->text('notes')->nullable();
            $table->text('resolution')->nullable();
            $table->timestamp('next_hearing_date')->nullable();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('barangay_blotter_hearings');
        Schema::dropIfExists('barangay_blotters');
    }
}
