"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapAlbum = exports.AlbumResponseDto = exports.UpdateAlbumUserDto = exports.AlbumStatisticsResponseDto = exports.GetAlbumsDto = exports.UpdateAlbumDto = exports.AlbumsAddAssetsResponseDto = exports.AlbumsAddAssetsDto = exports.CreateAlbumDto = exports.AlbumUserCreateDto = exports.AddUsersDto = exports.AlbumResponseSchema = void 0;
const openapi = require("@nestjs/swagger");
const nestjs_zod_1 = require("nestjs-zod");
const asset_ids_response_dto_1 = require("./asset-ids.response.dto");
const user_dto_1 = require("./user.dto");
const enum_1 = require("../enum");
const date_1 = require("../utils/date");
const validation_1 = require("../validation");
const zod_1 = __importDefault(require("zod"));
const AlbumUserAddSchema = zod_1.default
    .object({
    userId: zod_1.default.uuidv4().describe('User ID'),
    role: enum_1.AlbumUserRoleSchema.default(enum_1.AlbumUserRole.Editor).optional().describe('Album user role'),
})
    .meta({ id: 'AlbumUserAddDto' });
const AddUsersSchema = zod_1.default
    .object({
    albumUsers: zod_1.default.array(AlbumUserAddSchema).min(1).describe('Album users to add'),
})
    .meta({ id: 'AddUsersDto' });
const AlbumUserCreateSchema = zod_1.default
    .object({
    userId: zod_1.default.uuidv4().describe('User ID'),
    role: enum_1.AlbumUserRoleSchema,
})
    .meta({ id: 'AlbumUserCreateDto' });
const CreateAlbumSchema = zod_1.default
    .object({
    albumName: zod_1.default.string().describe('Album name'),
    description: zod_1.default.string().optional().describe('Album description'),
    albumUsers: zod_1.default.array(AlbumUserCreateSchema).optional().describe('Album users'),
    assetIds: zod_1.default.array(zod_1.default.uuidv4()).optional().describe('Initial asset IDs'),
})
    .meta({ id: 'CreateAlbumDto' });
const AlbumsAddAssetsSchema = zod_1.default
    .object({
    albumIds: zod_1.default.array(zod_1.default.uuidv4()).describe('Album IDs'),
    assetIds: zod_1.default.array(zod_1.default.uuidv4()).describe('Asset IDs'),
})
    .meta({ id: 'AlbumsAddAssetsDto' });
const AlbumsAddAssetsResponseSchema = zod_1.default
    .object({
    success: zod_1.default.boolean().describe('Operation success'),
    error: asset_ids_response_dto_1.BulkIdErrorReasonSchema.optional(),
})
    .meta({ id: 'AlbumsAddAssetsResponseDto' });
const UpdateAlbumSchema = zod_1.default
    .object({
    albumName: zod_1.default.string().optional().describe('Album name'),
    description: zod_1.default.string().optional().describe('Album description'),
    albumThumbnailAssetId: zod_1.default.uuidv4().optional().describe('Album thumbnail asset ID'),
    isActivityEnabled: zod_1.default.boolean().optional().describe('Enable activity feed'),
    order: enum_1.AssetOrderSchema.optional(),
})
    .meta({ id: 'UpdateAlbumDto' });
const GetAlbumsSchema = zod_1.default
    .object({
    id: zod_1.default.uuidv4().optional().describe('Album ID'),
    name: zod_1.default.string().optional().describe('Album name (exact match)'),
    isOwned: validation_1.stringToBool
        .optional()
        .describe('Filter by ownership: true = only owned, false = only shared-with-me, undefined = no filter'),
    isShared: validation_1.stringToBool
        .optional()
        .describe('Filter by shared status: true = only shared, false = not shared, undefined = no filter'),
    assetId: zod_1.default.uuidv4().optional().describe('Filter albums containing this asset ID (ignores other parameters)'),
})
    .meta({ id: 'GetAlbumsDto' });
const AlbumStatisticsResponseSchema = zod_1.default
    .object({
    owned: zod_1.default.int().min(0).describe('Number of owned albums'),
    shared: zod_1.default.int().min(0).describe('Number of shared albums'),
    notShared: zod_1.default.int().min(0).describe('Number of non-shared albums'),
})
    .meta({ id: 'AlbumStatisticsResponseDto' });
const UpdateAlbumUserSchema = zod_1.default
    .object({
    role: enum_1.AlbumUserRoleSchema,
})
    .meta({ id: 'UpdateAlbumUserDto' });
const AlbumUserResponseSchema = zod_1.default
    .object({
    user: user_dto_1.UserResponseSchema,
    role: enum_1.AlbumUserRoleSchema,
})
    .meta({ id: 'AlbumUserResponseDto' });
const ContributorCountResponseSchema = zod_1.default
    .object({
    userId: zod_1.default.uuidv4().describe('User ID'),
    assetCount: zod_1.default.int().min(0).describe('Number of assets contributed'),
})
    .meta({ id: 'ContributorCountResponseDto' });
exports.AlbumResponseSchema = zod_1.default
    .object({
    id: zod_1.default.uuidv4().describe('Album ID'),
    albumName: zod_1.default.string().describe('Album name'),
    description: zod_1.default.string().describe('Album description'),
    createdAt: zod_1.default.string().meta({ format: 'date-time' }).describe('Creation date'),
    updatedAt: zod_1.default.string().meta({ format: 'date-time' }).describe('Last update date'),
    albumThumbnailAssetId: zod_1.default.uuidv4().nullable().describe('Thumbnail asset ID'),
    shared: zod_1.default.boolean().describe('Is shared album'),
    albumUsers: zod_1.default
        .array(AlbumUserResponseSchema)
        .min(1)
        .describe('First entry is always the album owner. Second entry is the auth user, if it differs from the owner. The rest are ordered alphabetically.'),
    hasSharedLink: zod_1.default.boolean().describe('Has shared link'),
    assetCount: zod_1.default.int().min(0).describe('Number of assets'),
    lastModifiedAssetTimestamp: zod_1.default
        .string()
        .meta({ format: 'date-time' })
        .optional()
        .describe('Last modified asset timestamp'),
    startDate: zod_1.default.string().meta({ format: 'date-time' }).optional().describe('Start date (earliest asset)'),
    endDate: zod_1.default.string().meta({ format: 'date-time' }).optional().describe('End date (latest asset)'),
    isActivityEnabled: zod_1.default.boolean().describe('Activity feed enabled'),
    order: enum_1.AssetOrderSchema.optional(),
    contributorCounts: zod_1.default.array(ContributorCountResponseSchema).optional(),
})
    .meta({ id: 'AlbumResponseDto' });
class AddUsersDto extends (0, nestjs_zod_1.createZodDto)(AddUsersSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AddUsersDto = AddUsersDto;
class AlbumUserCreateDto extends (0, nestjs_zod_1.createZodDto)(AlbumUserCreateSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AlbumUserCreateDto = AlbumUserCreateDto;
class CreateAlbumDto extends (0, nestjs_zod_1.createZodDto)(CreateAlbumSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.CreateAlbumDto = CreateAlbumDto;
class AlbumsAddAssetsDto extends (0, nestjs_zod_1.createZodDto)(AlbumsAddAssetsSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AlbumsAddAssetsDto = AlbumsAddAssetsDto;
class AlbumsAddAssetsResponseDto extends (0, nestjs_zod_1.createZodDto)(AlbumsAddAssetsResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AlbumsAddAssetsResponseDto = AlbumsAddAssetsResponseDto;
class UpdateAlbumDto extends (0, nestjs_zod_1.createZodDto)(UpdateAlbumSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.UpdateAlbumDto = UpdateAlbumDto;
class GetAlbumsDto extends (0, nestjs_zod_1.createZodDto)(GetAlbumsSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.GetAlbumsDto = GetAlbumsDto;
class AlbumStatisticsResponseDto extends (0, nestjs_zod_1.createZodDto)(AlbumStatisticsResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AlbumStatisticsResponseDto = AlbumStatisticsResponseDto;
class UpdateAlbumUserDto extends (0, nestjs_zod_1.createZodDto)(UpdateAlbumUserSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.UpdateAlbumUserDto = UpdateAlbumUserDto;
class AlbumResponseDto extends (0, nestjs_zod_1.createZodDto)(exports.AlbumResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AlbumResponseDto = AlbumResponseDto;
class AlbumUserResponseDto extends (0, nestjs_zod_1.createZodDto)(AlbumUserResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
const mapAlbum = (entity) => {
    const albumUsers = [];
    if (entity.albumUsers) {
        for (const albumUser of entity.albumUsers) {
            const user = (0, user_dto_1.mapUser)(albumUser.user);
            albumUsers.push({
                user,
                role: albumUser.role,
            });
        }
    }
    const assets = entity.assets || [];
    const hasSharedLink = !!entity.sharedLinks && entity.sharedLinks.length > 0;
    const hasSharedUser = albumUsers.length > 1;
    let startDate = assets.at(0)?.localDateTime;
    let endDate = assets.at(-1)?.localDateTime;
    if (startDate && endDate && startDate > endDate) {
        [startDate, endDate] = [endDate, startDate];
    }
    return {
        albumName: entity.albumName,
        description: entity.description,
        albumThumbnailAssetId: entity.albumThumbnailAssetId,
        createdAt: (0, date_1.asDateTimeString)(entity.createdAt),
        updatedAt: (0, date_1.asDateTimeString)(entity.updatedAt),
        id: entity.id,
        albumUsers,
        shared: hasSharedUser || hasSharedLink,
        hasSharedLink,
        startDate: (0, date_1.asDateTimeString)(startDate),
        endDate: (0, date_1.asDateTimeString)(endDate),
        assetCount: entity.assets?.length || 0,
        isActivityEnabled: entity.isActivityEnabled,
        order: entity.order,
    };
};
exports.mapAlbum = mapAlbum;
//# sourceMappingURL=album.dto.js.map