/**
 * This file was automatically generated by openapi-codegeneration.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source OpenAPI file,
 * and run openapi-codegeneration to regenerate this file.
 */
import express from "express";
import operations from "../operations/index.js";
import { ValidationError } from "./types.js";
import { validateGetDevicesInput, validateGetDevicesOutput, validatePostDevicesInput, validatePostDevicesOutput, validateGetDevicesByDeviceIdInput, validateGetDevicesByDeviceIdOutput, validatePatchDevicesByDeviceIdInput, validatePatchDevicesByDeviceIdOutput, validateDeleteDevicesByDeviceIdInput, validateDeleteDevicesByDeviceIdOutput, validatePostDevicesByDeviceIdInput, validatePostDevicesByDeviceIdOutput, validateGetDevicesByDeviceIdAvailabilityInput, validateGetDevicesByDeviceIdAvailabilityOutput, validateDeleteDevicesByDeviceIdAvailabilityInput, validateDeleteDevicesByDeviceIdAvailabilityOutput, validatePostDevicesByDeviceIdAvailabilityInput, validatePostDevicesByDeviceIdAvailabilityOutput, validatePostDevicesByDeviceIdWebsocketInput, validatePostDevicesByDeviceIdWebsocketOutput, validatePostDevicesByDeviceIdSignalingInput, validatePostDevicesByDeviceIdSignalingOutput, validateGetPeerconnectionsInput, validateGetPeerconnectionsOutput, validatePostPeerconnectionsInput, validatePostPeerconnectionsOutput, validateGetPeerconnectionsByPeerconnectionIdInput, validateGetPeerconnectionsByPeerconnectionIdOutput, validateDeletePeerconnectionsByPeerconnectionIdInput, validateDeletePeerconnectionsByPeerconnectionIdOutput, validatePatchPeerconnectionsByPeerconnectionIdDeviceStatusInput, validatePatchPeerconnectionsByPeerconnectionIdDeviceStatusOutput } from "./requestValidation.js";
export default function router() {
    const router = express.Router();
    router.get("/devices", async (req, res, next) => {
        try {
            if (!validateGetDevicesInput()) {
                throw new ValidationError("Request validation failed", validateGetDevicesInput.errors, 400);
            }
            const result = await operations.getDevices(req);
            if (!validateGetDevicesOutput(result)) {
                throw new ValidationError("Response validation failed", validateGetDevicesOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.post("/devices", async (req, res, next) => {
        const parameters = {
            "changedUrl": req.query["changedUrl"]
        };
        const body = req.body;
        try {
            if (!validatePostDevicesInput(parameters, body)) {
                throw new ValidationError("Request validation failed", validatePostDevicesInput.errors, 400);
            }
            const result = await operations.postDevices(req, parameters, body);
            if (!validatePostDevicesOutput(result)) {
                throw new ValidationError("Response validation failed", validatePostDevicesOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.get("/devices/:device_id", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"],
            "flat_group": req.query["flat_group"] === "true"
        };
        try {
            if (!validateGetDevicesByDeviceIdInput(parameters)) {
                throw new ValidationError("Request validation failed", validateGetDevicesByDeviceIdInput.errors, 400);
            }
            const result = await operations.getDevicesByDeviceId(req, parameters);
            if (!validateGetDevicesByDeviceIdOutput(result)) {
                throw new ValidationError("Response validation failed", validateGetDevicesByDeviceIdOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.patch("/devices/:device_id", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"],
            "changedUrl": req.query["changedUrl"],
            "deletedUrl": req.query["deletedUrl"]
        };
        const body = req.body;
        try {
            if (!validatePatchDevicesByDeviceIdInput(parameters, body)) {
                throw new ValidationError("Request validation failed", validatePatchDevicesByDeviceIdInput.errors, 400);
            }
            const result = await operations.patchDevicesByDeviceId(req, parameters, body);
            if (!validatePatchDevicesByDeviceIdOutput(result)) {
                throw new ValidationError("Response validation failed", validatePatchDevicesByDeviceIdOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.delete("/devices/:device_id", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"]
        };
        try {
            if (!validateDeleteDevicesByDeviceIdInput(parameters)) {
                throw new ValidationError("Request validation failed", validateDeleteDevicesByDeviceIdInput.errors, 400);
            }
            const result = await operations.deleteDevicesByDeviceId(req, parameters);
            if (!validateDeleteDevicesByDeviceIdOutput(result)) {
                throw new ValidationError("Response validation failed", validateDeleteDevicesByDeviceIdOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.post("/devices/:device_id", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"],
            "changedUrl": req.query["changedUrl"]
        };
        try {
            if (!validatePostDevicesByDeviceIdInput(parameters)) {
                throw new ValidationError("Request validation failed", validatePostDevicesByDeviceIdInput.errors, 400);
            }
            const result = await operations.postDevicesByDeviceId(req, parameters);
            if (!validatePostDevicesByDeviceIdOutput(result)) {
                throw new ValidationError("Response validation failed", validatePostDevicesByDeviceIdOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.get("/devices/:device_id/availability", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"],
            "startTime": req.query["startTime"],
            "endTime": req.query["endTime"]
        };
        try {
            if (!validateGetDevicesByDeviceIdAvailabilityInput(parameters)) {
                throw new ValidationError("Request validation failed", validateGetDevicesByDeviceIdAvailabilityInput.errors, 400);
            }
            const result = await operations.getDevicesByDeviceIdAvailability(req, parameters);
            if (!validateGetDevicesByDeviceIdAvailabilityOutput(result)) {
                throw new ValidationError("Response validation failed", validateGetDevicesByDeviceIdAvailabilityOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.delete("/devices/:device_id/availability", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"]
        };
        try {
            if (!validateDeleteDevicesByDeviceIdAvailabilityInput(parameters)) {
                throw new ValidationError("Request validation failed", validateDeleteDevicesByDeviceIdAvailabilityInput.errors, 400);
            }
            const result = await operations.deleteDevicesByDeviceIdAvailability(req, parameters);
            if (!validateDeleteDevicesByDeviceIdAvailabilityOutput(result)) {
                throw new ValidationError("Response validation failed", validateDeleteDevicesByDeviceIdAvailabilityOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.post("/devices/:device_id/availability", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"]
        };
        const body = req.body;
        try {
            if (!validatePostDevicesByDeviceIdAvailabilityInput(parameters, body)) {
                throw new ValidationError("Request validation failed", validatePostDevicesByDeviceIdAvailabilityInput.errors, 400);
            }
            const result = await operations.postDevicesByDeviceIdAvailability(req, parameters, body);
            if (!validatePostDevicesByDeviceIdAvailabilityOutput(result)) {
                throw new ValidationError("Response validation failed", validatePostDevicesByDeviceIdAvailabilityOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.post("/devices/:device_id/websocket", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"]
        };
        try {
            if (!validatePostDevicesByDeviceIdWebsocketInput(parameters)) {
                throw new ValidationError("Request validation failed", validatePostDevicesByDeviceIdWebsocketInput.errors, 400);
            }
            const result = await operations.postDevicesByDeviceIdWebsocket(req, parameters);
            if (!validatePostDevicesByDeviceIdWebsocketOutput(result)) {
                throw new ValidationError("Response validation failed", validatePostDevicesByDeviceIdWebsocketOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.post("/devices/:device_id/signaling", async (req, res, next) => {
        const parameters = {
            "device_id": req.params["device_id"]
        };
        const body = req.body;
        try {
            if (!validatePostDevicesByDeviceIdSignalingInput(parameters, body)) {
                throw new ValidationError("Request validation failed", validatePostDevicesByDeviceIdSignalingInput.errors, 400);
            }
            const result = await operations.postDevicesByDeviceIdSignaling(req, parameters, body);
            if (!validatePostDevicesByDeviceIdSignalingOutput(result)) {
                throw new ValidationError("Response validation failed", validatePostDevicesByDeviceIdSignalingOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.get("/peerconnections", async (req, res, next) => {
        try {
            if (!validateGetPeerconnectionsInput()) {
                throw new ValidationError("Request validation failed", validateGetPeerconnectionsInput.errors, 400);
            }
            const result = await operations.getPeerconnections(req);
            if (!validateGetPeerconnectionsOutput(result)) {
                throw new ValidationError("Response validation failed", validateGetPeerconnectionsOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.post("/peerconnections", async (req, res, next) => {
        const parameters = {
            "closedUrl": req.query["closedUrl"],
            "statusChangedUrl": req.query["statusChangedUrl"]
        };
        const body = req.body;
        try {
            if (!validatePostPeerconnectionsInput(parameters, body)) {
                throw new ValidationError("Request validation failed", validatePostPeerconnectionsInput.errors, 400);
            }
            const result = await operations.postPeerconnections(req, parameters, body);
            if (!validatePostPeerconnectionsOutput(result)) {
                throw new ValidationError("Response validation failed", validatePostPeerconnectionsOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.get("/peerconnections/:peerconnection_id", async (req, res, next) => {
        const parameters = {
            "peerconnection_id": req.params["peerconnection_id"]
        };
        try {
            if (!validateGetPeerconnectionsByPeerconnectionIdInput(parameters)) {
                throw new ValidationError("Request validation failed", validateGetPeerconnectionsByPeerconnectionIdInput.errors, 400);
            }
            const result = await operations.getPeerconnectionsByPeerconnectionId(req, parameters);
            if (!validateGetPeerconnectionsByPeerconnectionIdOutput(result)) {
                throw new ValidationError("Response validation failed", validateGetPeerconnectionsByPeerconnectionIdOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.delete("/peerconnections/:peerconnection_id", async (req, res, next) => {
        const parameters = {
            "peerconnection_id": req.params["peerconnection_id"]
        };
        try {
            if (!validateDeletePeerconnectionsByPeerconnectionIdInput(parameters)) {
                throw new ValidationError("Request validation failed", validateDeletePeerconnectionsByPeerconnectionIdInput.errors, 400);
            }
            const result = await operations.deletePeerconnectionsByPeerconnectionId(req, parameters);
            if (!validateDeletePeerconnectionsByPeerconnectionIdOutput(result)) {
                throw new ValidationError("Response validation failed", validateDeletePeerconnectionsByPeerconnectionIdOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    router.patch("/peerconnections/:peerconnection_id/device_status", async (req, res, next) => {
        const parameters = {
            "peerconnection_id": req.params["peerconnection_id"],
            "device_url": req.query["device_url"]
        };
        const body = req.body;
        try {
            if (!validatePatchPeerconnectionsByPeerconnectionIdDeviceStatusInput(parameters, body)) {
                throw new ValidationError("Request validation failed", validatePatchPeerconnectionsByPeerconnectionIdDeviceStatusInput.errors, 400);
            }
            const result = await operations.patchPeerconnectionsByPeerconnectionIdDeviceStatus(req, parameters, body);
            if (!validatePatchPeerconnectionsByPeerconnectionIdDeviceStatusOutput(result)) {
                throw new ValidationError("Response validation failed", validatePatchPeerconnectionsByPeerconnectionIdDeviceStatusOutput.errors, 500);
            }
            for (const headerName in result.headers) {
                const header = result.headers[headerName];
                if (header) {
                    res.setHeader(headerName, header);
                }
            }
            return res.status(result.status).json(result.body);
        }
        catch (error) {
            next(error);
            return;
        }
    });
    return router;
}
//# sourceMappingURL=routes.js.map