<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('customer_tier', 20)->default('subscriber')->after('password');
            $table->string('status', 20)->default('active')->after('customer_tier');
        });

        DB::table('users')
            ->whereNull('customer_tier')
            ->orWhere('customer_tier', '')
            ->update(['customer_tier' => 'subscriber']);

        DB::table('users')
            ->whereNull('status')
            ->orWhere('status', '')
            ->update(['status' => 'active']);
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['customer_tier', 'status']);
        });
    }
};

