<?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('price_adjustment_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->string('adjustment_type');
            $table->string('operation');
            $table->string('price_type');
            $table->decimal('adjustment_value', 10, 2);
            $table->integer('products_updated');
            $table->text('notes')->nullable();
            $table->timestamps();
        });

        Schema::create('price_adjustment_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('price_adjustment_log_id')->constrained()->onDelete('cascade');
            $table->foreignId('product_id')->constrained()->onDelete('cascade');
            $table->decimal('old_cost_price', 10, 2);
            $table->decimal('new_cost_price', 10, 2);
            $table->decimal('old_selling_price', 10, 2);
            $table->decimal('new_selling_price', 10, 2);
            $table->timestamps();
        });
    }

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