<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('shop_goods_receipt_items', function (Blueprint $table) {
            $table->id();
            $table->string('shop_id', 255)->index();
            $table->string('code', 255);
            $table->string('goods_receipt_code', 255)->index();
            $table->string('stock_code', 255);
            $table->string('product_code', 255)->index();
            $table->integer('quantity')->default(0);
            $table->decimal('length', 10, 2)->nullable();
            $table->decimal('unit_price', 10, 2)->default(0);
            $table->decimal('total_price', 10, 2)->default(0);
            $table->dateTime('local_db_created_at');
            $table->timestamps();

            $table->unique(['shop_id', 'code', 'local_db_created_at'], 'unique_shop_code_created');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('shop_goods_receipt_items');
    }
};
