<?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_invoice_returns', function (Blueprint $table) {
            $table->id();
            $table->string('shop_id', 255)->index();
            $table->string('code', 255)->index();
            $table->string('invoice_code', 255)->index();
            $table->string('branch_code', 255);
            $table->decimal('total_amount', 12, 2)->default(0);
            $table->date('return_date');
            $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_invoice_returns');
    }
};
