"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get createPrinterSchema () {
        return createPrinterSchema;
    },
    get printerApiKeyValidator () {
        return printerApiKeyValidator;
    },
    get printerDateAddedValidator () {
        return printerDateAddedValidator;
    },
    get printerDisabledReasonValidator () {
        return printerDisabledReasonValidator;
    },
    get printerEnabledValidator () {
        return printerEnabledValidator;
    },
    get printerNameValidator () {
        return printerNameValidator;
    },
    get printerPasswordValidator () {
        return printerPasswordValidator;
    },
    get printerTypeValidator () {
        return printerTypeValidator;
    },
    get printerUrlValidator () {
        return printerUrlValidator;
    },
    get printerUsernameValidator () {
        return printerUsernameValidator;
    },
    get refineApiKeyValidator () {
        return refineApiKeyValidator;
    },
    get updatePrinterDisabledReasonSchema () {
        return updatePrinterDisabledReasonSchema;
    },
    get updatePrinterEnabledSchema () {
        return updatePrinterEnabledSchema;
    }
});
const _serviceconstants = require("../../constants/service.constants");
const _printerapiinterface = require("../printer-api.interface");
const _zod = require("zod");
const octoPrintApiKeySchema = _zod.z.string().min(_serviceconstants.apiKeyLengthMinDefault).max(_serviceconstants.apiKeyLengthMaxDefault).regex(/^[a-zA-Z0-9_-]+$/, "Alpha-numeric, dash, and underscore only");
const printerApiKeyValidator = _zod.z.string().optional();
const printerNameValidator = _zod.z.string();
const printerUsernameValidator = _zod.z.string();
const printerPasswordValidator = _zod.z.string();
const printerEnabledValidator = _zod.z.boolean();
const printerDisabledReasonValidator = _zod.z.string().optional();
const printerUrlValidator = _zod.z.string().url();
const printerTypeValidator = _zod.z.nativeEnum(_printerapiinterface.PrinterTypesEnum);
const printerDateAddedValidator = _zod.z.number().optional();
const prusaLinkAuthSchema = _zod.z.object({
    username: printerUsernameValidator,
    password: printerPasswordValidator
});
const basePrinterSchema = _zod.z.object({
    dateAdded: printerDateAddedValidator,
    printerURL: printerUrlValidator,
    printerType: printerTypeValidator,
    apiKey: printerApiKeyValidator,
    username: printerUsernameValidator.optional(),
    password: printerPasswordValidator.optional(),
    enabled: printerEnabledValidator.optional(),
    name: printerNameValidator
}).strip();
const apiKeyPrinterTypeSchema = _zod.z.object({
    apiKey: printerApiKeyValidator,
    printerType: printerTypeValidator,
    username: printerUsernameValidator.optional(),
    password: printerPasswordValidator.optional()
});
const refineApiKeyValidator = (data, ctx)=>{
    if (data.printerType === _printerapiinterface.OctoprintType) {
        const result = octoPrintApiKeySchema.safeParse(data.apiKey);
        if (!result.success) {
            result.error.issues.forEach((issue)=>{
                ctx.addIssue({
                    ...issue,
                    path: [
                        "apiKey",
                        ...issue.path
                    ]
                });
            });
        }
    } else if (data.printerType === _printerapiinterface.PrusaLinkType || data.printerType === _printerapiinterface.BambuType) {
        const result = prusaLinkAuthSchema.safeParse({
            username: data.username,
            password: data.password
        });
        if (!result.success) {
            result.error.issues.forEach((issue)=>{
                ctx.addIssue({
                    ...issue,
                    path: [
                        "username",
                        ...issue.path
                    ]
                });
                ctx.addIssue({
                    ...issue,
                    path: [
                        "password",
                        ...issue.path
                    ]
                });
            });
        }
    }
};
const createPrinterSchema = basePrinterSchema.superRefine(refineApiKeyValidator);
const updatePrinterEnabledSchema = _zod.z.object({
    enabled: printerEnabledValidator
});
const updatePrinterDisabledReasonSchema = _zod.z.object({
    disabledReason: printerDisabledReasonValidator,
    enabled: printerEnabledValidator.optional()
});

//# sourceMappingURL=printer-service.validation.js.map