<?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('material_prices', function (Blueprint $table) {
            $table->id();
            $table->foreignId('material_id')->constrained()->onDelete('cascade');
            $table->tinyInteger('sisi')->default(1)->comment('Jumlah sisi cetak: 1 atau 2');
            $table->integer('min_qty')->default(1)->comment('Qty minimal (inclusive)');
            $table->integer('max_qty')->nullable()->comment('Qty maksimal (inclusive), null = unlimited');
            $table->decimal('price', 15, 2)->default(0);
            $table->timestamps();

            $table->index(['material_id', 'sisi', 'min_qty']);
        });
    }

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