import { curateEntity } from './entities.js';

export function curateMedia(media, context = {}) {
	if (!media) {
		return null;
	}

	const mime = media.mime.split('/');

	return {
		id: media.id,
		hash: media.hash,
		path: media.path,
		thumbnail: media.thumbnail,
		lazy: media.lazy,
		isS3: media.is_s3,
		width: media.width,
		height: media.height,
		index: media.index,
		sharpness: media.sharpness,
		entropy: media.entropy,
		credit: media.credit,
		mime: mime && {
			type: mime[0],
			subtype: mime[1],
		},
		comment: media.comment,
		entity: media.entity && curateEntity({
			...media.entity,
			parent: media.entity_parent,
		}),
		type: context.type || null,
		sfw: curateMedia(media.sfw_media),
		isRestricted: context.isRestricted,
		biometrics: media.biometrics
			? {
					...media.biometrics.biometrics,
					width: media.biometrics.width,
					height: media.biometrics.height,
				}
			: null,
		createdAt: media.created_at,
	};
}
