<?php

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

class AddTailorPortalStatus extends Migration
{
    public function up()
    {
        if (Schema::hasTable('curtains') && !Schema::hasColumn('curtains', 'tailor_status')) {
            Schema::table('curtains', function (Blueprint $table) {
                $table->string('tailor_status')->default('received')->after('is_paid');
            });
        }

        if (Schema::hasTable('roles')) {
            DB::table('roles')->updateOrInsert(
                ['name' => 'Tailor'],
                [
                    'description' => 'Tailor account with limited order access',
                    'guard_name' => 'web',
                    'is_active' => true,
                    'updated_at' => now(),
                    'created_at' => now(),
                ]
            );
        }
    }

    public function down()
    {
        if (Schema::hasTable('curtains') && Schema::hasColumn('curtains', 'tailor_status')) {
            Schema::table('curtains', function (Blueprint $table) {
                $table->dropColumn('tailor_status');
            });
        }
    }
}
