<?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::create('sales_orders', function (Blueprint $table) {

            $table->id();

            $table->string('order_no',30)->unique();

            $table->foreignId('client_id')
                ->constrained('clients')
                ->cascadeOnDelete();

            $table->date('order_date');

            $table->decimal('total_amount',12,2)->default(0);

            $table->decimal('discount_amount',12,2)->default(0);

            $table->decimal('tax_amount',12,2)->default(0);

            $table->decimal('grand_total',12,2)->default(0);

            $table->text('remarks')->nullable();

            $table->enum('status',[
                'Draft',
                'Confirmed',
                'Completed',
                'Cancelled'
            ])->default('Draft');

            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();

            $table->timestamps();

            $table->softDeletes();

            $table->index(['client_id']);
            $table->index(['order_date']);
            $table->index(['status']);
        });
    }

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