<?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('gold_records', function (Blueprint $table) {
            $table->id();
            $table->string('customer_name')->nullable();
            $table->decimal('weight', 10, 4);        // Total weight in grams
            $table->decimal('laser_points', 10, 4);  // Laser purity points e.g. 99.66
            $table->decimal('rate_per_tola', 15, 2); // Rate (R) per tola
            $table->decimal('ch_charges', 15, 2)->default(0); // CH charges
            $table->decimal('lbr_charges', 15, 2)->default(0); // LBR charges
            // Calculated fields stored for record
            $table->decimal('pure_weight', 10, 4)->nullable();
            $table->decimal('impure_weight', 10, 4)->nullable();
            $table->decimal('tola', 10, 4)->nullable();
            $table->decimal('ratti', 10, 4)->nullable();   // ratti OUT
            $table->decimal('ratti_in', 10, 4)->nullable(); // ratti IN
            $table->decimal('price', 15, 2)->nullable();
            $table->decimal('total_price', 15, 2)->nullable();
            $table->timestamps();
        });
    }

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