<?php

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

class CreateOrdersTable extends Migration
{
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id');
            $table->integer('branch_id')->nullable();

            $table->string('full_name')->nullable();
            $table->bigInteger('phone')->nullable();
            $table->unsignedInteger('legal_id')->nullable();
            $table->unsignedInteger('address_id')->nullable();

            $table->boolean('with_installation')->default(false);
            $table->enum('client_type', ['physical', 'legal'])->nullable();
            $table->enum('payment_type', ['bank', 'cash', 'click', 'payme']);
            $table->boolean('with_didox')->default(false);
            $table->enum('delivery_type', ['delivery', 'pickup'])->default('delivery');
            $table->timestamp('shipment_date')->nullable();
            $table->timestamp('accepted_at')->nullable();
            $table->jsonb('currency')->nullable();
            $table->enum('status', ['processing', 'collected', 'waiting_buyer', 'in_way', 'closed', 'cancelled', 'replacement', 'completed'])->default('processing');
            $table->enum('payment_status', ['waiting', 'cancelled', 'payed', 'cash', 'review'])->default('waiting');

            $table->boolean('archived')->default(false);

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

    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
