/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { vertexvis } from "@vertexvis/frame-streaming-protos";
import { clamp } from "@vertexvis/geometry";
import { Mapper as M } from "@vertexvis/utils";
import { toPbRGBi } from "./material";
import { toPbFloatValue, toPbStringValue } from "./scalar";
const toPbFrameType = M.defineMapper((type) => {
    switch (type) {
        case 'all':
            return {
                enabled: { value: true },
                frameType: vertexvis.protobuf.stream.FrameType.FRAME_TYPE_ALL,
            };
        case 'final':
            return {
                enabled: { value: true },
                frameType: vertexvis.protobuf.stream.FrameType.FRAME_TYPE_FINAL,
            };
        default:
            return {
                enabled: { value: false },
                frameType: vertexvis.protobuf.stream.FrameType.FRAME_TYPE_INVALID,
            };
    }
}, (type) => type);
const toPbPhantom = M.defineMapper(M.read(M.ifDefined(M.getProp('opacity'))), ([opacity]) => ({
    opacity: { value: clamp(opacity !== null && opacity !== void 0 ? opacity : 0, 0, 1) },
}));
const toPbFeatureLines = M.defineMapper(M.read(M.ifDefined(M.getProp('width')), M.ifDefined(M.mapProp('color', M.ifDefined(toPbRGBi)))), ([lineWidth, lineColor]) => ({ lineWidth, lineColor }));
const toPbSelectionHighlighting = M.defineMapper(M.read(M.ifDefined(M.mapProp('color', M.ifDefined(toPbRGBi))), M.ifDefined(M.mapProp('opacity', toPbFloatValue)), M.ifDefined(M.getProp('lineWidth'))), ([color, opacity, lineWidth]) => {
    if (color || opacity || lineWidth) {
        return {
            color,
            opacity,
            lineWidth,
        };
    }
    else
        return undefined;
});
const toPbFeatureHighlight = M.defineMapper(M.read(M.ifDefined(M.mapProp('highlightColor', M.ifDefined(toPbRGBi))), M.ifDefined(M.mapProp('occludedOpacity', toPbFloatValue)), M.ifDefined(M.mapProp('outline', M.ifDefined(toPbFeatureLines)))), ([highlightColor, occludedOpacity, outline]) => ({
    highlightColor,
    occludedOpacity,
    outline,
}));
const toPbNoDefaultLights = M.defineMapper((noDefaultLights) => !!noDefaultLights, (attr) => attr);
const toPbExperimentalRenderingOptions = M.defineMapper((experimentalRenderingOptions) => experimentalRenderingOptions !== null && experimentalRenderingOptions !== void 0 ? experimentalRenderingOptions : '', (attr) => attr);
const toPbFrameOptions = M.defineMapper(M.read(M.ifDefined(M.mapProp('frameBackgroundColor', M.ifDefined(toPbRGBi)))), ([frameBackgroundColor]) => ({ frameBackgroundColor }));
const toPbSceneComparison = M.defineMapper(M.read(M.ifDefined(M.mapProp('streamKeyToCompare', M.ifDefined(toPbStringValue)))), ([streamKeyToCompare]) => ({
    streamKeyToCompare,
}));
const toPbCrossSectioning = M.defineMapper(M.read(M.ifDefined(M.mapProp('endCapEnabled', (endCapEnabled) => !!endCapEnabled)), M.ifDefined(M.mapProp('endCapColor', M.ifDefined(toPbRGBi)))), ([endCapEnabled, endCapColor]) => ({
    endCapEnabled,
    endCapColor,
}));
export const toPbStreamAttributes = M.defineMapper(M.read(M.mapProp('depthBuffers', toPbFrameType), M.mapProp('phantom', toPbPhantom), M.mapProp('noDefaultLights', toPbNoDefaultLights), M.mapProp('featureLines', toPbFeatureLines), M.mapProp('featureHighlighting', toPbFeatureHighlight), M.mapProp('featureMaps', toPbFrameType), M.mapProp('experimentalRenderingOptions', toPbExperimentalRenderingOptions), M.mapProp('selectionHighlighting', toPbSelectionHighlighting), M.mapProp('frames', toPbFrameOptions), M.mapProp('sceneComparison', toPbSceneComparison), M.mapProp('crossSectioning', toPbCrossSectioning)), ([db, pi, ndl, fl, fh, fm, ero, hs, fa, sc, cs]) => {
    const value = {
        depthBuffers: db,
        phantomItems: pi,
        noDefaultLights: ndl,
        featureLines: fl,
        featureHighlighting: fh,
        featureMaps: fm,
        experimentalRenderingOptions: ero,
        selectionHighlighting: hs,
        frames: fa,
        sceneComparison: sc,
        crossSectioningAttributes: cs,
    };
    return value;
});
//# sourceMappingURL=streamAttributes.js.map
