<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('job_packages', function (Blueprint $table) {
            // Tambah semua kolom yang dibutuhkan
            $table->string('name')->after('id');
            $table->foreignId('ppk_id')->after('name')->constrained('users');
            $table->enum('job_type', ['konstruksi', 'konsultasi'])->after('ppk_id');
            $table->string('sub_classification')->after('job_type');
            $table->decimal('budget', 15, 2)->after('sub_classification');
            $table->string('province')->after('budget');
            $table->string('regency')->after('province');
            $table->string('district')->after('regency');
            $table->string('village')->after('district');
            $table->integer('duration_days')->after('village');
            $table->text('description')->nullable()->after('duration_days');
            $table->enum('status', [
                'draft', 'active', 'matching', 'selected',
                'contracting', 'execution', 'completed', 'cancelled'
            ])->default('draft')->after('description');
            $table->timestamp('matched_at')->nullable()->after('status');
            $table->foreignId('selected_contractor_id')->nullable()->after('matched_at')->constrained('contractors');
            $table->foreignId('contract_id')->nullable()->after('selected_contractor_id')->constrained('contracts');
            $table->softDeletes();
        });
    }

    public function down(): void
    {
        Schema::table('job_packages', function (Blueprint $table) {
            $table->dropColumn([
                'name', 'ppk_id', 'job_type', 'sub_classification', 'budget',
                'province', 'regency', 'district', 'village', 'duration_days',
                'description', 'status', 'matched_at', 'selected_contractor_id',
                'contract_id', 'deleted_at'
            ]);
        });
    }
};