"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deviceValidationMiddleware = void 0;
const deviceValidationMiddleware = (deviceRepository) => {
    return async (req, res, next) => {
        const deviceId = req.headers['x-device-id'];
        if (typeof deviceId !== 'string' || !deviceId) {
            res.status(400).json({
                success: false,
                code: 'DEVICE_ID_REQUIRED',
                message: 'x-device-id header is required',
            });
            return;
        }
        const device = await deviceRepository.findById(deviceId);
        if (!device) {
            res.status(404).json({
                success: false,
                code: 'DEVICE_NOT_FOUND',
                message: 'Device not found',
            });
            return;
        }
        res.locals.deviceId = deviceId;
        next();
    };
};
exports.deviceValidationMiddleware = deviceValidationMiddleware;
//# sourceMappingURL=device-validation.middleware.js.map