<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('projects', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->nullable()->constrained('users'); // کارفرما
            $table->foreignId('producer_id')->nullable()->constrained('producers');
            $table->foreignId('category_id')->nullable()->constrained('categories');
            
            $table->string('name');
            $table->text('excerpt')->nullable();
            $table->text('desc')->nullable();
            
            $table->dateTime('start_date')->nullable();
            $table->dateTime('end_date')->nullable();
            $table->dateTime('deadline')->nullable();
            $table->enum('status', ['pending', 'active', 'completed', 'cancelled', 'expired'])->default('pending');
            
            $table->decimal('budget', 15, 0)->nullable();
            $table->json('budgets')->nullable(); // بودجه‌های مختلف
            
            $table->foreignId('province_id')->nullable()->constrained('provinces');
            $table->foreignId('county_id')->nullable()->constrained('counties');
            $table->text('address')->nullable();
            
            $table->json('requirements')->nullable();
            $table->json('attachments')->nullable();
            $table->text('notes')->nullable();
            
            $table->integer('view_count')->default(0);
            $table->integer('request_count')->default(0);

            $table->foreignId('created_by')->constrained('users');
            $table->foreignId('updated_by')->nullable()->constrained('users');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('projects');
    }
};
