<?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('finance_sales_entries', function (Blueprint $table) {
            $table->string('id', 120)->primary();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->date('date');
            $table->decimal('kg_sold', 14, 3)->default(0);
            $table->decimal('price_crc_per_kg', 14, 2)->default(0);
            $table->decimal('total_crc', 14, 2)->default(0);
            $table->string('customer_name')->nullable();
            $table->json('scope_json')->nullable();
            $table->text('notes')->nullable();
            $table->timestamp('created_at_client')->nullable();
            $table->timestamp('updated_at_client')->nullable();
            $table->timestamps();

            $table->index(['user_id', 'date']);
        });
    }

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