<?php

namespace Modules\MedRegistry\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Schema;
use Modules\MedRegistry\Support\CatalogSync;

/**
 * P1-T3 — seeds/refreshes the host-global module catalog from the nwidart
 * manifests: reads each module.json `extra.medical` block when present, else
 * the curated retro-fit map in Support\CatalogSync (existing modules are never
 * edited). Idempotent (updateOrCreate on module_key); also re-run weekly via
 * `medreg:sync-catalog`.
 */
class MedregCatalogSeeder extends Seeder
{
    public function run(): void
    {
        if (! Schema::hasTable('medreg_modules')) {
            return;
        }

        $summary = (new CatalogSync())->sync();

        if ($this->command) {
            $this->command->info(sprintf(
                'MedRegistry catalog synced: %d modules present, %d marked absent.',
                $summary['synced'],
                $summary['marked_absent']
            ));
        }
    }
}
