<?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('addresses', function (Blueprint $table) {
            $table->id();
            $table->string('recipient_name', 50);
            $table->string('phone');
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('province_code', 10);
            $table->string('city_code', 10);
            $table->string('district_code', 10);
            $table->string('village_code', 10);
            $table->string('street')->nullable();
            $table->text('address_detail')->nullable();
            $table->decimal('latitude', 10, 7)->nullable();
            $table->decimal('longitude', 10, 7)->nullable();

            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
{
    Schema::table('addresses', function (Blueprint $table) {
        $table->dropForeign(['user_id']);
    });

    Schema::dropIfExists('addresses');
}
};
