<?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('suppliers', function (Blueprint $t) {
            $t->id();
            $t->foreignId('company_id')->constrained()->cascadeOnDelete();

            $t->string('name');
            $t->string('contact_name')->nullable();
            $t->string('phone')->nullable();
            $t->string('email')->nullable();
            $t->string('website')->nullable();

            $t->string('pay_terms')->nullable();           // "Net 30", "Avans", "La livrare"
            $t->unsignedSmallInteger('delivery_days')->default(0);
            $t->unsignedTinyInteger('rating')->default(3); // 1-5
            $t->decimal('discount_pct', 5, 2)->default(0);
            $t->json('categories')->nullable();            // ["Frâne","Ulei"...]

            $t->boolean('is_active')->default(true);
            $t->text('notes')->nullable();

            $t->timestamps();
            $t->softDeletes();

            $t->index(['company_id', 'is_active']);
        });
    }

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