<?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('transfer_orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('store_id')->index();
            $table->string('transfer_no', 50)->unique();
            $table->unsignedBigInteger('from_warehouse_id');
            $table->unsignedBigInteger('to_warehouse_id');
            $table->json('items')->nullable();
            $table->tinyInteger('status')->default(0)->comment('0待确认1已确认2已取消');
            $table->unsignedBigInteger('operator_id')->nullable();
            $table->string('remark', 500)->nullable();
            $table->timestamps();

            $table->foreign('from_warehouse_id')->references('id')->on('warehouses');
            $table->foreign('to_warehouse_id')->references('id')->on('warehouses');
        });

        Schema::create('inventory_checks', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('store_id')->index();
            $table->string('check_no', 50)->unique();
            $table->unsignedBigInteger('warehouse_id');
            $table->json('items')->nullable()->comment('[{material_id,book_qty,actual_qty,diff_qty,remark}]');
            $table->tinyInteger('status')->default(0)->comment('0草稿1盘点中2已完成');
            $table->string('finish_remark', 500)->nullable();
            $table->unsignedBigInteger('operator_id')->nullable();
            $table->timestamps();

            $table->foreign('warehouse_id')->references('id')->on('warehouses');
        });
    }

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