<?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', function (Blueprint $table) {
            $table->id();
            $table->string('invoice_no', 50)->nullable()->index();
            $table->foreignId('product_id')->constrained('products')->cascadeOnDelete();
            $table->string('product_name', 100)->index();
            $table->string('product_code', 100)->index();
            $table->string('color', 50)->nullable();
            $table->integer('quantity_sold');
            $table->decimal('selling_price', 10, 2);
            $table->decimal('discount', 10, 2)->default(0);
            $table->decimal('original_price', 10, 2)->nullable();
            $table->decimal('total_amount', 10, 2);
            $table->decimal('profit', 10, 2)->nullable();
            $table->decimal('due_amount', 10, 2)->default(0);
            $table->string('customer_name', 100)->nullable()->index();
            $table->string('customer_phone', 20)->nullable()->index();
            $table->string('customer_address', 255)->nullable();
            $table->timestamp('sales_date')->nullable()->useCurrent();
            $table->date('sale_date')->nullable()->index();
        });
    }

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