<?php

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

class CreateOrderServicesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orderServices', function (Blueprint $table) {
            $table->id();
            $table->text('code');
            $table->json('answers')->nullable();
            $table->timestamp('time_todo');
            $table->json('meta')->nullable();
            $table->enum('status',\Mehrab\OrderService\Models\OrderService::$status)->default(\Mehrab\OrderService\Models\OrderService::PENDING_OPERATOR);
            $table->json('price')->nullable();
            $table->json('reports')->nullable();
            $table->timestamps();

            $table->foreignId('user_id')
                ->nullable()
                ->constrained('users', 'id')
                ->onDelete('SET NULL');

            $table->foreignId('service_id')
                ->nullable()
                ->constrained('services', 'id')
                ->onDelete('SET NULL');

            $table->foreignId('region_id')
                ->nullable()
                ->constrained('regions', 'id')
                ->onDelete('SET NULL');

            $table->foreignId('media_id')
                ->nullable()
                ->constrained('media', 'id')
                ->onDelete('SET NULL');

            $table->foreignId('operator_id')
                ->nullable()
                ->constrained('users', 'id')
                ->onDelete('SET NULL');

            $table->foreignId('team_leader_id')
                ->nullable()
                ->constrained('users', 'id')
                ->onDelete('SET NULL');

            $table->foreignId('expert_id')
                ->nullable()
                ->constrained('users', 'id')
                ->onDelete('SET NULL');

        });
    }

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