<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('tenant_packages') || ! Schema::hasTable('packages')) {
            return;
        }

        DB::table('tenant_packages')
            ->whereIn('package_id', function ($query) {
                $query->select('id')
                    ->from('packages')
                    ->where('type', 'endcustomer');
            })
            ->update([
                'expires_at' => now()->addCentury(),
                'active' => true,
                'updated_at' => now(),
            ]);
    }

    public function down(): void
    {
        // No rollback – endcustomer packages should remain non-expiring.
    }
};
