/**
 * Media upload folders — one per module that owns photos / videos.
 * The folder name is the second segment of the storage key
 * (`{subdomain}/{folder}/{filename}`) so it must stay URL-safe and
 * must never be derived from user input other than via this list.
 */
export const MEDIA_FOLDERS = [
  'hotels',
  'activities',
  'vehicles',
  'suppliers',
  'destinations',
  'trip-sources',
  'service-types',
  'vehicle-types',
] as const;

export type MediaFolder = (typeof MEDIA_FOLDERS)[number];

export type MediaType = 'image' | 'video';

export interface MediaPolicy {
  allowVideo: boolean;
  maxImages: number;
  maxVideos: number;
}

const GALLERY_POLICY: MediaPolicy = { allowVideo: true, maxImages: 20, maxVideos: 5 };

export const MEDIA_POLICIES: Record<MediaFolder, MediaPolicy> = {
  hotels: GALLERY_POLICY,
  activities: GALLERY_POLICY,
  vehicles: { allowVideo: false, maxImages: 20, maxVideos: 0 },
  suppliers: { allowVideo: false, maxImages: 1, maxVideos: 0 },
  destinations: GALLERY_POLICY,
  'trip-sources': GALLERY_POLICY,
  'service-types': GALLERY_POLICY,
  'vehicle-types': GALLERY_POLICY,
};

export const MAX_IMAGE_BYTES = 10 * 1024 * 1024;
export const MAX_VIDEO_BYTES = 50 * 1024 * 1024;

/** First key segment for trashed media. Reserved — no tenant may use it as a subdomain. */
export const DELETED_MEDIA_ROOT = 'deleted';

const MEDIA_FOLDER_SET = new Set<string>(MEDIA_FOLDERS);

export function isMediaFolder(value: string): value is MediaFolder {
  return MEDIA_FOLDER_SET.has(value);
}
