<?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_contacts', function (Blueprint $table) {
            $table->id();
            $table->string('shop_id', 255)->index();
            $table->string('code', 255)->index();
            $table->enum('contact_type', ['customer', 'supplier']);
            $table->string('name', 255);
            $table->string('phone', 50)->nullable();
            $table->text('address')->nullable();
            $table->decimal('credit_limit', 12, 2)->default(0);
            $table->string('branch_code', 255);
            $table->dateTime('local_db_created_at');
            $table->timestamps();

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

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