"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SystemConfigDto = exports.SystemConfigTemplateStorageOptionDto = exports.SystemConfigSmtpDto = exports.SystemConfigFFmpegDto = exports.SystemConfigSchema = exports.ReleaseChannel = void 0;
exports.mapConfig = mapConfig;
const openapi = require("@nestjs/swagger");
const cron_1 = require("cron");
const nestjs_zod_1 = require("nestjs-zod");
const model_config_dto_1 = require("./model-config.dto");
const enum_1 = require("../enum");
const zod_1 = __importDefault(require("zod"));
const configBool = zod_1.default
    .preprocess((val) => {
    if (val === 'true') {
        return true;
    }
    if (val === 'false') {
        return false;
    }
    return val;
}, zod_1.default.boolean())
    .meta({ type: 'boolean' });
const JobSettingsSchema = zod_1.default
    .object({
    concurrency: zod_1.default.int().min(1).describe('Concurrency'),
})
    .meta({ id: 'JobSettingsDto' });
const cronExpressionSchema = zod_1.default
    .string()
    .superRefine((value, ctx) => {
    const validated = (0, cron_1.validateCronExpression)(value);
    if (!validated.valid) {
        ctx.addIssue({
            code: 'custom',
            message: `Invalid cron expression. ${validated.error?.message ?? ''}`,
            input: value,
        });
    }
})
    .describe('Cron expression');
const DatabaseBackupSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    cronExpression: cronExpressionSchema,
    keepLastAmount: zod_1.default.int().min(1).describe('Keep last amount'),
})
    .meta({ id: 'DatabaseBackupConfig' });
const SystemConfigIntegrityJobSchema = zod_1.default
    .object({
    enabled: zod_1.default.boolean().describe('Enabled'),
    cronExpression: cronExpressionSchema.describe('Cron expression for when the integrity check should run'),
})
    .describe('Integrity job config')
    .meta({ id: 'SystemConfigIntegrityJob' });
const SystemConfigIntegrityChecksumJobSchema = SystemConfigIntegrityJobSchema.extend({
    timeLimit: zod_1.default.int().nonnegative().describe('How long the integrity checksum job may run for'),
    percentageLimit: zod_1.default
        .float32()
        .nonnegative()
        .max(1)
        .describe('Percentage limit of the integrity checksum job')
        .meta({ format: 'double' }),
})
    .describe('Integrity checksum job config')
    .meta({ id: 'SystemConfigIntegrityChecksumJob' });
const SystemConfigIntegrityChecksSchema = zod_1.default
    .object({
    missingFiles: SystemConfigIntegrityJobSchema,
    untrackedFiles: SystemConfigIntegrityJobSchema,
    checksumFiles: SystemConfigIntegrityChecksumJobSchema,
})
    .describe('Integrity checks config')
    .meta({ id: 'SystemConfigIntegrityChecks' });
const SystemConfigBackupsSchema = zod_1.default.object({ database: DatabaseBackupSchema }).meta({ id: 'SystemConfigBackupsDto' });
const SystemConfigFFmpegSchema = zod_1.default
    .object({
    crf: zod_1.default.coerce.number().int().min(0).max(51).describe('CRF'),
    threads: zod_1.default.coerce.number().int().min(0).describe('Threads'),
    preset: zod_1.default.string().describe('Preset'),
    targetVideoCodec: enum_1.VideoCodecSchema,
    acceptedVideoCodecs: zod_1.default.array(enum_1.VideoCodecSchema).describe('Accepted video codecs'),
    targetAudioCodec: enum_1.AudioCodecSchema,
    acceptedAudioCodecs: zod_1.default.array(enum_1.AudioCodecSchema).describe('Accepted audio codecs'),
    acceptedContainers: zod_1.default.array(enum_1.VideoContainerSchema).describe('Accepted containers'),
    targetResolution: zod_1.default.string().describe('Target resolution'),
    maxBitrate: zod_1.default.string().describe('Max bitrate'),
    bframes: zod_1.default.coerce.number().int().min(-1).max(16).describe('B-frames'),
    refs: zod_1.default.coerce.number().int().min(0).max(6).describe('References'),
    gopSize: zod_1.default.coerce.number().int().min(0).describe('GOP size'),
    temporalAQ: configBool.describe('Temporal AQ'),
    cqMode: enum_1.CQModeSchema,
    twoPass: configBool.describe('Two pass'),
    preferredHwDevice: zod_1.default.string().describe('Preferred hardware device'),
    transcode: enum_1.TranscodePolicySchema,
    accel: enum_1.TranscodeHardwareAccelerationSchema,
    accelDecode: configBool.describe('Accelerated decode'),
    tonemap: enum_1.ToneMappingSchema,
    realtime: zod_1.default
        .object({
        enabled: configBool.describe('Enable real-time HLS transcoding (alpha)'),
        videoCodecs: zod_1.default.array(enum_1.VideoCodecSchema).describe('Video codecs to use for real-time HLS transcoding'),
        resolutions: zod_1.default.array(enum_1.HlsVideoResolutionSchema).describe('Resolutions to use for real-time HLS transcoding'),
    })
        .meta({ id: 'SystemConfigFFmpegRealtimeDto' }),
})
    .meta({ id: 'SystemConfigFFmpegDto' });
const SystemConfigJobSchema = zod_1.default
    .object({
    thumbnailGeneration: JobSettingsSchema,
    metadataExtraction: JobSettingsSchema,
    videoConversion: JobSettingsSchema,
    faceDetection: JobSettingsSchema,
    smartSearch: JobSettingsSchema,
    backgroundTask: JobSettingsSchema,
    migration: JobSettingsSchema,
    search: JobSettingsSchema,
    sidecar: JobSettingsSchema,
    library: JobSettingsSchema,
    notifications: JobSettingsSchema,
    ocr: JobSettingsSchema,
    workflow: JobSettingsSchema,
    editor: JobSettingsSchema,
    integrityCheck: JobSettingsSchema,
})
    .meta({ id: 'SystemConfigJobDto' });
const SystemConfigLibraryScanSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    cronExpression: cronExpressionSchema,
})
    .meta({ id: 'SystemConfigLibraryScanDto' });
const SystemConfigLibraryWatchSchema = zod_1.default
    .object({ enabled: configBool.describe('Enabled') })
    .meta({ id: 'SystemConfigLibraryWatchDto' });
const SystemConfigLibrarySchema = zod_1.default
    .object({ scan: SystemConfigLibraryScanSchema, watch: SystemConfigLibraryWatchSchema })
    .meta({ id: 'SystemConfigLibraryDto' });
const SystemConfigLoggingSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    level: enum_1.LogLevelSchema,
})
    .meta({ id: 'SystemConfigLoggingDto' });
const MachineLearningAvailabilityChecksSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    timeout: zod_1.default.int(),
    interval: zod_1.default.int(),
})
    .meta({ id: 'MachineLearningAvailabilityChecksDto' });
const SystemConfigMachineLearningSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    urls: zod_1.default.array(zod_1.default.string()).min(1).describe('ML service URLs'),
    availabilityChecks: MachineLearningAvailabilityChecksSchema,
    clip: model_config_dto_1.CLIPConfigSchema,
    duplicateDetection: model_config_dto_1.DuplicateDetectionConfigSchema,
    facialRecognition: model_config_dto_1.FacialRecognitionConfigSchema,
    ocr: model_config_dto_1.OcrConfigSchema,
})
    .meta({ id: 'SystemConfigMachineLearningDto' });
const SystemConfigMapSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    lightStyle: zod_1.default.url().describe('Light map style URL'),
    darkStyle: zod_1.default.url().describe('Dark map style URL'),
})
    .meta({ id: 'SystemConfigMapDto' });
var ReleaseChannel;
(function (ReleaseChannel) {
    ReleaseChannel["Stable"] = "stable";
    ReleaseChannel["ReleaseCandidate"] = "releaseCandidate";
})(ReleaseChannel || (exports.ReleaseChannel = ReleaseChannel = {}));
const ReleaseChannelSchema = zod_1.default.enum(ReleaseChannel).describe('Release channel').meta({ id: 'ReleaseChannel' });
const SystemConfigNewVersionCheckSchema = zod_1.default
    .object({ enabled: configBool.describe('Enabled'), channel: ReleaseChannelSchema })
    .meta({ id: 'SystemConfigNewVersionCheckDto' });
const SystemConfigNightlyTasksSchema = zod_1.default
    .object({
    startTime: zod_1.default.iso
        .time({
        precision: -1,
        error: (iss) => `Invalid input: expected string in HH:MM format, received ${typeof iss.input}`,
    })
        .describe('Start time (HH:MM)'),
    databaseCleanup: configBool.describe('Database cleanup'),
    missingThumbnails: configBool.describe('Missing thumbnails'),
    clusterNewFaces: configBool.describe('Cluster new faces'),
    generateMemories: configBool.describe('Generate memories'),
    syncQuotaUsage: configBool.describe('Sync quota usage'),
})
    .meta({ id: 'SystemConfigNightlyTasksDto' });
const SystemConfigOAuthSchema = zod_1.default
    .object({
    autoLaunch: configBool.describe('Auto launch'),
    autoRegister: configBool.describe('Auto register'),
    buttonText: zod_1.default.string().describe('Button text'),
    clientId: zod_1.default.string().describe('Client ID'),
    clientSecret: zod_1.default.string().describe('Client secret'),
    tokenEndpointAuthMethod: enum_1.OAuthTokenEndpointAuthMethodSchema,
    timeout: zod_1.default.int().min(1).describe('Timeout'),
    allowInsecureRequests: configBool.describe('Allow insecure requests'),
    defaultStorageQuota: zod_1.default.int().min(0).nullable().describe('Default storage quota'),
    enabled: configBool.describe('Enabled'),
    issuerUrl: zod_1.default
        .string()
        .refine((url) => url.length === 0 || zod_1.default.url().safeParse(url).success, {
        error: 'Issuer URL must be an empty string or a valid URL',
    })
        .describe('Issuer URL'),
    scope: zod_1.default.string().describe('Scope'),
    prompt: zod_1.default.string().describe('OAuth prompt parameter (e.g. select_account, login, consent)'),
    endSessionEndpoint: zod_1.default
        .string()
        .refine((url) => url.length === 0 || zod_1.default.url().safeParse(url).success, {
        error: 'endSessionEndpoint must be an empty string or a valid URL',
    })
        .describe('End session endpoint'),
    signingAlgorithm: zod_1.default.string().describe('Signing algorithm'),
    profileSigningAlgorithm: zod_1.default.string().describe('Profile signing algorithm'),
    storageLabelClaim: zod_1.default.string().describe('Storage label claim'),
    storageQuotaClaim: zod_1.default.string().describe('Storage quota claim'),
    roleClaim: zod_1.default.string().describe('Role claim'),
    mobileOverrideEnabled: configBool.describe('Mobile override enabled'),
    mobileRedirectUri: zod_1.default.string().describe('Mobile redirect URI (set to empty string to disable)'),
})
    .transform((value, ctx) => {
    if (!value.mobileOverrideEnabled || value.mobileRedirectUri === '') {
        return value;
    }
    if (!zod_1.default.url().safeParse(value.mobileRedirectUri).success) {
        ctx.issues.push({
            code: 'custom',
            message: 'Mobile redirect URI must be an empty string or a valid URL',
            input: value.mobileRedirectUri,
        });
        return zod_1.default.NEVER;
    }
    return value;
})
    .meta({
    id: 'SystemConfigOAuthDto',
});
const SystemConfigPasswordLoginSchema = zod_1.default
    .object({ enabled: configBool.describe('Enabled') })
    .meta({ id: 'SystemConfigPasswordLoginDto' });
const SystemConfigReverseGeocodingSchema = zod_1.default
    .object({ enabled: configBool.describe('Enabled') })
    .meta({ id: 'SystemConfigReverseGeocodingDto' });
const SystemConfigFacesSchema = zod_1.default
    .object({ import: configBool.describe('Import') })
    .meta({ id: 'SystemConfigFacesDto' });
const SystemConfigMetadataSchema = zod_1.default.object({ faces: SystemConfigFacesSchema }).meta({ id: 'SystemConfigMetadataDto' });
const SystemConfigServerSchema = zod_1.default
    .object({
    externalDomain: zod_1.default
        .string()
        .refine((url) => url.length === 0 || zod_1.default.url().safeParse(url).success, {
        error: 'External domain must be an empty string or a valid URL',
    })
        .describe('External domain'),
    loginPageMessage: zod_1.default.string().describe('Login page message'),
    publicUsers: configBool.describe('Public users'),
})
    .meta({ id: 'SystemConfigServerDto' });
const SystemConfigSmtpTransportSchema = zod_1.default
    .object({
    ignoreCert: configBool.describe('Whether to ignore SSL certificate errors'),
    host: zod_1.default.string().describe('SMTP server hostname'),
    port: zod_1.default.int().min(0).max(65_535).describe('SMTP server port'),
    secure: configBool.describe('Whether to use secure connection (TLS/SSL)'),
    username: zod_1.default.string().describe('SMTP username'),
    password: zod_1.default.string().describe('SMTP password'),
})
    .meta({ id: 'SystemConfigSmtpTransportDto' });
const SystemConfigSmtpSchema = zod_1.default
    .object({
    enabled: configBool.describe('Whether SMTP email notifications are enabled'),
    from: zod_1.default.string().describe('Email address to send from'),
    replyTo: zod_1.default.string().describe('Email address for replies'),
    transport: SystemConfigSmtpTransportSchema,
})
    .meta({ id: 'SystemConfigSmtpDto' });
const SystemConfigNotificationsSchema = zod_1.default
    .object({ smtp: SystemConfigSmtpSchema })
    .meta({ id: 'SystemConfigNotificationsDto' });
const SystemConfigTemplateEmailsSchema = zod_1.default
    .object({
    albumInviteTemplate: zod_1.default.string().describe('Album invite template'),
    welcomeTemplate: zod_1.default.string().describe('Welcome template'),
    albumUpdateTemplate: zod_1.default.string().describe('Album update template'),
})
    .meta({ id: 'SystemConfigTemplateEmailsDto' });
const SystemConfigTemplatesSchema = zod_1.default
    .object({ email: SystemConfigTemplateEmailsSchema })
    .meta({ id: 'SystemConfigTemplatesDto' });
const SystemConfigStorageTemplateSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    hashVerificationEnabled: configBool.describe('Hash verification enabled'),
    template: zod_1.default.string().describe('Template'),
})
    .meta({ id: 'SystemConfigStorageTemplateDto' });
const SystemConfigTemplateStorageOptionSchema = zod_1.default
    .object({
    yearOptions: zod_1.default.array(zod_1.default.string()).describe('Available year format options for storage template'),
    monthOptions: zod_1.default.array(zod_1.default.string()).describe('Available month format options for storage template'),
    weekOptions: zod_1.default.array(zod_1.default.string()).describe('Available week format options for storage template'),
    dayOptions: zod_1.default.array(zod_1.default.string()).describe('Available day format options for storage template'),
    hourOptions: zod_1.default.array(zod_1.default.string()).describe('Available hour format options for storage template'),
    minuteOptions: zod_1.default.array(zod_1.default.string()).describe('Available minute format options for storage template'),
    secondOptions: zod_1.default.array(zod_1.default.string()).describe('Available second format options for storage template'),
    presetOptions: zod_1.default.array(zod_1.default.string()).describe('Available preset template options'),
})
    .meta({ id: 'SystemConfigTemplateStorageOptionDto' });
const SystemConfigThemeSchema = zod_1.default
    .object({ customCss: zod_1.default.string().describe('Custom CSS for theming') })
    .meta({ id: 'SystemConfigThemeDto' });
const SystemConfigGeneratedImageSchema = zod_1.default
    .object({
    format: enum_1.ImageFormatSchema,
    quality: zod_1.default.int().min(1).max(100).describe('Quality'),
    size: zod_1.default.int().min(1).describe('Size'),
    progressive: configBool.default(false).optional().describe('Progressive'),
})
    .meta({ id: 'SystemConfigGeneratedImageDto' });
const SystemConfigGeneratedFullsizeImageSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    format: enum_1.ImageFormatSchema,
    quality: zod_1.default.int().min(1).max(100).describe('Quality'),
    progressive: configBool.default(false).optional().describe('Progressive'),
})
    .meta({ id: 'SystemConfigGeneratedFullsizeImageDto' });
const SystemConfigImageSchema = zod_1.default
    .object({
    thumbnail: SystemConfigGeneratedImageSchema,
    preview: SystemConfigGeneratedImageSchema,
    fullsize: SystemConfigGeneratedFullsizeImageSchema,
    colorspace: enum_1.ColorspaceSchema,
    extractEmbedded: configBool.describe('Extract embedded'),
})
    .meta({ id: 'SystemConfigImageDto' });
const SystemConfigTrashSchema = zod_1.default
    .object({
    enabled: configBool.describe('Enabled'),
    days: zod_1.default.int().min(0).describe('Days'),
})
    .meta({ id: 'SystemConfigTrashDto' });
const SystemConfigUserSchema = zod_1.default
    .object({
    deleteDelay: zod_1.default.int().min(1).describe('Delete delay'),
})
    .meta({ id: 'SystemConfigUserDto' });
exports.SystemConfigSchema = zod_1.default
    .object({
    backup: SystemConfigBackupsSchema,
    ffmpeg: SystemConfigFFmpegSchema,
    logging: SystemConfigLoggingSchema,
    machineLearning: SystemConfigMachineLearningSchema,
    map: SystemConfigMapSchema,
    newVersionCheck: SystemConfigNewVersionCheckSchema,
    nightlyTasks: SystemConfigNightlyTasksSchema,
    oauth: SystemConfigOAuthSchema,
    passwordLogin: SystemConfigPasswordLoginSchema,
    reverseGeocoding: SystemConfigReverseGeocodingSchema,
    metadata: SystemConfigMetadataSchema,
    storageTemplate: SystemConfigStorageTemplateSchema,
    job: SystemConfigJobSchema,
    image: SystemConfigImageSchema,
    trash: SystemConfigTrashSchema,
    theme: SystemConfigThemeSchema,
    library: SystemConfigLibrarySchema,
    notifications: SystemConfigNotificationsSchema,
    templates: SystemConfigTemplatesSchema,
    server: SystemConfigServerSchema,
    user: SystemConfigUserSchema,
    integrityChecks: SystemConfigIntegrityChecksSchema,
})
    .describe('System configuration')
    .meta({ id: 'SystemConfigDto' });
class SystemConfigFFmpegDto extends (0, nestjs_zod_1.createZodDto)(SystemConfigFFmpegSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SystemConfigFFmpegDto = SystemConfigFFmpegDto;
class SystemConfigSmtpDto extends (0, nestjs_zod_1.createZodDto)(SystemConfigSmtpSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SystemConfigSmtpDto = SystemConfigSmtpDto;
class SystemConfigTemplateStorageOptionDto extends (0, nestjs_zod_1.createZodDto)(SystemConfigTemplateStorageOptionSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SystemConfigTemplateStorageOptionDto = SystemConfigTemplateStorageOptionDto;
class SystemConfigDto extends (0, nestjs_zod_1.createZodDto)(exports.SystemConfigSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SystemConfigDto = SystemConfigDto;
function mapConfig(config) {
    return config;
}
//# sourceMappingURL=system-config.dto.js.map