/** Doctor media sections mapped to R2 folder segments. */
export const DOCTOR_MEDIA_SECTIONS = [
  "doctor-photo",
  "before-after",
  "gallery",
  "certificates",
] as const

export type DoctorMediaSection = (typeof DOCTOR_MEDIA_SECTIONS)[number]

/** Hospital media sections mapped to R2 folder segments. */
export const HOSPITAL_MEDIA_SECTIONS = [
  "main-photo",
  "gallery",
  "before-after",
  "certificates",
] as const

export type HospitalMediaSection = (typeof HOSPITAL_MEDIA_SECTIONS)[number]

/**
 * Procedure media folders under `procedures/{slug}/…`:
 * Main hero image, Before & After hero strip (basic), Before & After gallery, Overview, Reviews.
 */
export const PROCEDURE_MEDIA_SECTIONS = [
  "main-photo",
  "before-after-hero",
  "before-after-gallery",
  "overview",
  "reviews",
] as const

export type ProcedureMediaSection = (typeof PROCEDURE_MEDIA_SECTIONS)[number]

/** Article media sections mapped to R2 folder segments. */
export const ARTICLE_MEDIA_SECTIONS = [
  "cover-image",
  "content-images",
  "gallery",
  "seo-images",
] as const

export type ArticleMediaSection = (typeof ARTICLE_MEDIA_SECTIONS)[number]

/** Client-side staged file before commit to R2. */
export interface StagedImage {
  id: string
  file: File
  previewUrl: string
  fileName: string
}

export interface MediaFileNamingOptions {
  /** Dashboard section label for the file (e.g. reviews, overview). Defaults to `section`. */
  fileBaseName?: string
  /** Zero-based index when multiple images share a section. */
  fileIndex?: number
  filePart?: "before" | "after"
}

export interface CommitDoctorImageInput extends MediaFileNamingOptions {
  entity?: "doctor"
  staged: StagedImage
  doctorName: string
  section: DoctorMediaSection
  doctorId?: string
}

export interface CommitHospitalImageInput extends MediaFileNamingOptions {
  entity: "hospital"
  staged: StagedImage
  hospitalSlug: string
  section: HospitalMediaSection
  hospitalId?: string
}

export interface CommitProcedureImageInput extends MediaFileNamingOptions {
  entity: "procedure"
  staged: StagedImage
  procedureSlug: string
  section: ProcedureMediaSection
  procedureId?: string
}

export interface CommitArticleImageInput extends MediaFileNamingOptions {
  entity: "article"
  staged: StagedImage
  articleSlug: string
  section: ArticleMediaSection
  articleId?: string
}

export type CommitImageInput =
  | CommitDoctorImageInput
  | CommitHospitalImageInput
  | CommitProcedureImageInput
  | CommitArticleImageInput

export interface CommittedImage {
  url: string
  publicId: string
  objectKey: string
  mediaKey: string
}
