<?php

use App\Enums\EntityStatus;
use App\Enums\PaymentMethod;
use App\Enums\SalesType;
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('sales', function (Blueprint $table) {
            $table->id();
            $table->string('social_reason')->nullable();
            $table->date('creation_date')->nullable();
            $table->string('nit')->nullable();
            $table->enum('status', [SalesType::PRESALE->value, SalesType::SALE->value, SalesType::DELIVERY->value, SalesType::DISCARD->value ])->default(SalesType::SALE->value);
            $table->enum('payment_method', [PaymentMethod::DIRECTCREDIT->value, PaymentMethod::CASH->value, PaymentMethod::BANKCREDIT->value]);
            $table->date('delivery_date')->nullable();
            $table->float('amount',15,2)->nullable();
            $table->float('initial_fee',15,2)->nullable();
            $table->boolean('is_payment_initial_fee')->default(false);
            $table->integer('discount')->nullable();
            $table->enum('entity_status',[EntityStatus::ACTIVE->value, EntityStatus::INACTIVE->value])->default(EntityStatus::ACTIVE->value);
            $table->unsignedBigInteger('opportunity_id')->nullable();
            $table->foreign('opportunity_id')->references('id')->on('opportunities');
            $table->unsignedBigInteger('quote_id')->nullable();
            $table->foreign('quote_id')->references('id')->on('quotes');
            $table->timestamps();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->unsignedBigInteger('deleted_by')->nullable();
            $table->foreign('created_by')->references('id')->on('users');
            $table->foreign('updated_by')->references('id')->on('users');
            $table->foreign('deleted_by')->references('id')->on('users');
            $table->softDeletes();
        });
    }
    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('sales');
    }
};
