import { SETTINGS_PROJECTION_AREAS, SETTINGS_PROJECTION_PUBLIC_SOURCE, SETTINGS_PROJECTION_STATUSES, SETTINGS_PROJECTION_TONES, readSettingsLabel, toneForSettingsStatus, } from "./settingsProjectionContract.js";
const AREA_SET = new Set(SETTINGS_PROJECTION_AREAS);
const STATUS_SET = new Set(SETTINGS_PROJECTION_STATUSES);
const TONE_SET = new Set(SETTINGS_PROJECTION_TONES);
export class SettingsProjectionService {
    store;
    constructor(store) {
        this.store = store;
    }
    listForWorkspace(workspaceId) {
        const items = [];
        if (workspaceId) {
            const rows = this.store.listSettingsReadiness(workspaceId);
            for (const row of rows) {
                if (!AREA_SET.has(row.area))
                    continue;
                if (!STATUS_SET.has(row.status))
                    continue;
                const label = readSettingsLabel(row.displayLabel);
                if (!label)
                    continue;
                const status = row.status;
                const tone = TONE_SET.has(row.tone)
                    ? row.tone
                    : toneForSettingsStatus(status);
                items.push({
                    source: SETTINGS_PROJECTION_PUBLIC_SOURCE,
                    id: row.id,
                    workspaceId: row.workspaceId,
                    area: row.area,
                    status,
                    tone,
                    displayLabel: label,
                    lastErrorCode: readSettingsLabel(row.lastErrorCode ?? null),
                });
            }
        }
        return {
            contractVersion: "v1",
            generatedAt: new Date().toISOString(),
            items,
        };
    }
}
