import { existsSync, readFileSync } from "node:fs";
import { createHash } from "node:crypto";
import { resolve } from "node:path";
import { createThreeCompatPMREMDiagnostics } from "./PMREMPreset.js";
export function verifyThreeCompatHdriFile(preset) {
    if (preset.kind !== "real-hdri" || !preset.localPath || !preset.sha256) {
        return preset.kind === "procedural-hdr";
    }
    const file = resolve(preset.localPath);
    if (!existsSync(file))
        return false;
    const data = readFileSync(file);
    return createHash("sha256").update(data).digest("hex") === preset.sha256;
}
export function createThreeCompatEnvironmentDiagnostics(preset) {
    const [width, height] = preset.resolution;
    const bytesPerPixel = preset.format === "rgbe-hdr" ? 4 : 8;
    const memoryBytes = width * height * bytesPerPixel;
    const pmrem = createThreeCompatPMREMDiagnostics(preset.pmrem, preset.format);
    return {
        id: preset.id,
        kind: preset.kind,
        resolution: preset.resolution,
        format: preset.format,
        memoryBytes: memoryBytes + pmrem.estimatedBytes,
        pmrem,
        warnings: [
            ...(width < 1024 || height < 512 ? ["Environment resolution is below ThreeCompat minimum."] : []),
            ...(preset.kind === "real-hdri" && !verifyThreeCompatHdriFile(preset) ? ["Real HDRI source is missing or sha256 verification failed."] : []),
            ...pmrem.warnings
        ]
    };
}
//# sourceMappingURL=HDRIEnvironment.js.map