"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SharedLinkResponseDto = exports.SharedLinkLoginDto = exports.SharedLinkEditDto = exports.SharedLinkCreateDto = exports.SharedLinkSearchDto = void 0;
exports.mapSharedLink = mapSharedLink;
const openapi = require("@nestjs/swagger");
const nestjs_zod_1 = require("nestjs-zod");
const decorators_1 = require("../decorators");
const album_dto_1 = require("./album.dto");
const asset_response_dto_1 = require("./asset-response.dto");
const enum_1 = require("../enum");
const validation_1 = require("../validation");
const zod_1 = __importDefault(require("zod"));
const SharedLinkSearchSchema = zod_1.default
    .object({
    albumId: zod_1.default.uuidv4().optional().describe('Filter by album ID'),
    id: zod_1.default
        .uuidv4()
        .optional()
        .describe('Filter by shared link ID')
        .meta(new decorators_1.HistoryBuilder().added('v2.5.0').getExtensions()),
})
    .meta({ id: 'SharedLinkSearchDto' });
const SharedLinkCreateSchema = zod_1.default
    .object({
    type: enum_1.SharedLinkTypeSchema,
    assetIds: zod_1.default.array(zod_1.default.uuidv4()).optional().describe('Asset IDs (for individual assets)'),
    albumId: zod_1.default.uuidv4().optional().describe('Album ID (for album sharing)'),
    description: zod_1.default.string().nullable().optional().describe('Link description'),
    password: zod_1.default.string().nullable().optional().describe('Link password'),
    slug: zod_1.default.string().nullable().optional().describe('Custom URL slug'),
    expiresAt: validation_1.isoDatetimeToDate.nullable().describe('Expiration date').default(null).optional(),
    allowUpload: zod_1.default.boolean().optional().describe('Allow uploads'),
    allowDownload: zod_1.default.boolean().default(true).optional().describe('Allow downloads'),
    showMetadata: zod_1.default.boolean().default(true).optional().describe('Show metadata'),
})
    .meta({ id: 'SharedLinkCreateDto' });
const SharedLinkEditSchema = zod_1.default
    .object({
    description: zod_1.default.string().nullable().optional().describe('Link description'),
    password: zod_1.default.string().nullable().optional().describe('Link password'),
    slug: zod_1.default.string().nullable().optional().describe('Custom URL slug'),
    expiresAt: validation_1.isoDatetimeToDate.nullish().describe('Expiration date'),
    allowUpload: zod_1.default.boolean().optional().describe('Allow uploads'),
    allowDownload: zod_1.default.boolean().optional().describe('Allow downloads'),
    showMetadata: zod_1.default.boolean().optional().describe('Show metadata'),
})
    .meta({ id: 'SharedLinkEditDto' });
const SharedLinkLoginSchema = zod_1.default
    .object({
    password: zod_1.default.string().describe('Shared link password').meta({ example: 'password' }),
})
    .meta({ id: 'SharedLinkLoginDto' });
const SharedLinkResponseSchema = zod_1.default
    .object({
    id: zod_1.default.uuidv4().describe('Shared link ID'),
    description: zod_1.default.string().nullable().describe('Link description'),
    password: zod_1.default.string().nullable().describe('Has password'),
    userId: zod_1.default.uuidv4().describe('Owner user ID'),
    key: zod_1.default.string().describe('Encryption key (base64url)'),
    type: enum_1.SharedLinkTypeSchema,
    createdAt: validation_1.isoDatetimeToDate.describe('Creation date'),
    expiresAt: validation_1.isoDatetimeToDate.nullable().describe('Expiration date'),
    assets: zod_1.default.array(asset_response_dto_1.AssetResponseSchema),
    album: album_dto_1.AlbumResponseSchema.optional(),
    allowUpload: zod_1.default.boolean().describe('Allow uploads'),
    allowDownload: zod_1.default.boolean().describe('Allow downloads'),
    showMetadata: zod_1.default.boolean().describe('Show metadata'),
    slug: zod_1.default.string().nullable().describe('Custom URL slug'),
})
    .describe('Shared link response')
    .meta({ id: 'SharedLinkResponseDto' });
class SharedLinkSearchDto extends (0, nestjs_zod_1.createZodDto)(SharedLinkSearchSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SharedLinkSearchDto = SharedLinkSearchDto;
class SharedLinkCreateDto extends (0, nestjs_zod_1.createZodDto)(SharedLinkCreateSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SharedLinkCreateDto = SharedLinkCreateDto;
class SharedLinkEditDto extends (0, nestjs_zod_1.createZodDto)(SharedLinkEditSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SharedLinkEditDto = SharedLinkEditDto;
class SharedLinkLoginDto extends (0, nestjs_zod_1.createZodDto)(SharedLinkLoginSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SharedLinkLoginDto = SharedLinkLoginDto;
class SharedLinkResponseDto extends (0, nestjs_zod_1.createZodDto)(SharedLinkResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SharedLinkResponseDto = SharedLinkResponseDto;
function mapSharedLink(sharedLink, options) {
    const assets = sharedLink.assets || [];
    const response = {
        id: sharedLink.id,
        description: sharedLink.description,
        password: sharedLink.password,
        userId: sharedLink.userId,
        key: sharedLink.key.toString('base64url'),
        type: sharedLink.type,
        createdAt: sharedLink.createdAt,
        expiresAt: sharedLink.expiresAt,
        assets: assets.map((asset) => (0, asset_response_dto_1.mapAsset)(asset, { stripMetadata: options.stripAssetMetadata })),
        album: sharedLink.album ? (0, album_dto_1.mapAlbum)(sharedLink.album) : undefined,
        allowUpload: sharedLink.allowUpload,
        allowDownload: sharedLink.allowDownload,
        showMetadata: sharedLink.showExif,
        slug: sharedLink.slug,
    };
    if (response.album) {
        response.album.hasSharedLink = true;
        response.album.shared = true;
    }
    return response;
}
//# sourceMappingURL=shared-link.dto.js.map