    <?php

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

    return new class extends Migration
    {
        public function up(): void
        {
            Schema::create('easypaisa_customers', function (Blueprint $table) {

                // ── Primary Key ───────────────────────────────────────────────
                $table->id('customer_id');

                // ── Easypaisa Identity Fields ─────────────────────────────────
                $table->string('msisdn', 20)->unique()->comment('Easypaisa mobile number / MSISDN');
                $table->string('open_id', 100)->unique()->nullable()->comment('Easypaisa OAuth OpenID');
                $table->string('auth_id', 100)->unique()->nullable()->comment('Easypaisa AuthID from OAuth flow');
                $table->string('union_id', 100)->unique()->nullable()->comment('Easypaisa UnionID for cross-app identity');
                $table->string('customer_eful_number', 50)->unique()->nullable()->comment('EFUL policy/reference number assigned to customer');

                // ── Personal Information ──────────────────────────────────────
                $table->string('full_name', 150)->comment('Customer full name as per CNIC');
                $table->string('cnic', 15)->unique()->comment('CNIC format: XXXXX-XXXXXXX-X');
                $table->date('dob')->comment('Date of birth');
                $table->enum('gender', ['male', 'female', 'other'])->nullable();
                $table->enum('marital_status', ['single', 'married', 'divorced', 'widowed'])->nullable();

                // ── Contact & Address ─────────────────────────────────────────
                $table->string('email', 150)->nullable()->unique();
                $table->text('address')->nullable()->comment('Full postal address');
                $table->string('city', 100)->nullable();
                $table->string('province', 100)->nullable();
                $table->string('country', 100)->default('Pakistan');
                $table->string('postal_code', 10)->nullable();

                // ── Geo Location ──────────────────────────────────────────────
                $table->decimal('latitude', 10, 7)->nullable()->comment('GPS latitude');
                $table->decimal('longitude', 10, 7)->nullable()->comment('GPS longitude');

                // ── Avatar / Media ────────────────────────────────────────────
                $table->string('user_avatar', 500)->nullable()->comment('URL or path to profile picture');

                // ── Account Status & Verification ────────────────────────────
                $table->boolean('is_active')->default(true)->comment('Account active/inactive');
                $table->boolean('is_verified')->default(false)->comment('CNIC/KYC verified');
                $table->boolean('is_easypaisa_verified')->default(false)->comment('Verified via Easypaisa OAuth');
                $table->timestamp('easypaisa_verified_at')->nullable();
                $table->timestamp('cnic_verified_at')->nullable();
                $table->timestamp('last_login_at')->nullable();

                // ── Device & Session ──────────────────────────────────────────
                $table->string('device_token', 500)->nullable()->comment('FCM/APNS push notification token');
                $table->enum('device_type', ['android', 'ios', 'web'])->nullable();
                $table->string('app_version', 20)->nullable()->comment('Last known app version');

                // ── Soft Delete & Timestamps ──────────────────────────────────
                $table->softDeletes();
                $table->timestamps();

                // ── Indexes ───────────────────────────────────────────────────
                $table->index('full_name');
                $table->index('is_active');
                $table->index('open_id');
                $table->index(['latitude', 'longitude']);
            });
        }

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