<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('suppliers', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('fiscal_code', 16)->nullable();
            $table->string('vat', 16)->nullable();
            $table->string('address')->nullable();
            $table->string('zip_code', 5)->nullable();
            $table->unsignedBigInteger('nation_id')->nullable();
            $table->foreign('nation_id')->nullable()->references('id')->on('nations')->onUpdate('cascade')->onDelete('cascade');
            $table->unsignedBigInteger('province_id')->nullable();
            $table->foreign('province_id')->nullable()->references('id')->on('provinces')->onUpdate('cascade')->onDelete('cascade');
            $table->unsignedBigInteger('city_id')->nullable();
            $table->foreign('city_id')->nullable()->references('id')->on('cities')->onUpdate('cascade')->onDelete('cascade');
            $table->string('referent')->nullable();
            $table->string('website')->nullable();
            $table->string('phone')->nullable();
            $table->string('email')->nullable();
            $table->integer('enabled')->default(1);

            $table->string('referent_first_name')->nullable();
            $table->string('referent_last_name')->nullable();
            $table->string('referent_email')->nullable();
            $table->string('referent_phone')->nullable();
            $table->string('referent_mobile')->nullable();

            $table->softDeletes();
            $table->timestamps();
        });
    }

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