<?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('offers', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->constrained('users'); // پیشنهاد دهنده
            $table->foreignId('offer_to')->nullable()->constrained('users'); // پیشنهاد به
            $table->foreignId('product_id')->nullable()->constrained('products');
            $table->foreignId('project_id')->nullable()->constrained('projects');
            
            $table->string('name');
            $table->text('description')->nullable();
            $table->enum('offer_type', ['دمآرد', 'هنیزه'])->nullable(); // دمآرد/هنیزه
            $table->enum('contract_type', ['ناموت', 'other'])->nullable();
            
            $table->decimal('price', 15, 2)->nullable();
            $table->integer('quantity')->nullable();
            $table->string('unit')->nullable();
            
            $table->dateTime('offer_date');
            $table->dateTime('expiry_date')->nullable();
            $table->date('contract_start_date')->nullable();
            $table->date('contract_end_date')->nullable();
            $table->integer('duration_days')->nullable();
            
            $table->enum('status', ['pending', 'accepted', 'rejected', 'expired', 'cancelled'])->default('pending');
            
            $table->json('specifications')->nullable();
            $table->text('notes')->nullable();

            $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('offers');
    }
};
