<?php

namespace App\Support;

use Illuminate\Support\Facades\Schema;
use Throwable;

class ApiCenterSchema
{
    public const TABLES = [
        'products',
        'client_accounts',
        'licenses',
        'releases',
        'changelog_entries',
        'api_logs',
    ];

    public function missingTables(): array
    {
        try {
            return array_values(array_filter(
                self::TABLES,
                fn (string $table) => ! Schema::hasTable($table)
            ));
        } catch (Throwable) {
            return self::TABLES;
        }
    }

    public function ready(): bool
    {
        return $this->missingTables() === [];
    }
}
