<?php

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

class CreatePcProductStatusTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('pc_product_status')) {
            return;
        }

        Schema::create('pc_product_status', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('business_id');
            $table->unsignedInteger('product_id');

            // Set when an operator confirms the parsed/enriched data is correct.
            $table->timestamp('checked_at')->nullable();
            $table->unsignedInteger('checked_by')->nullable();
            // Set when the legacy product_custom_field* data is wiped (only allowed after checked_at).
            $table->timestamp('custom_fields_cleared_at')->nullable();

            $table->timestamps();

            $table->unique(['business_id', 'product_id'], 'pc_product_status_unique');
        });
    }

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