import type { DriveFileInfo } from "@/lib/api/types"

function demoNow(): string {
  const d = new Date()
  d.setHours(14, 30, 0, 0)
  return d.toISOString().replace(/\.\d{3}Z$/, "+00:00")
}

function demoDaysAgo(days: number, hours = 14, minutes = 30): string {
  const d = new Date()
  d.setDate(d.getDate() - days)
  d.setHours(hours, minutes, 0, 0)
  return d.toISOString().replace(/\.\d{3}Z$/, "+00:00")
}

function file(
  partial: Omit<
    DriveFileInfo,
    "etag" | "last_modified" | "size" | "mime_type" | "type" | "is_favorite" | "is_shared"
  > &
    Partial<
      Pick<
        DriveFileInfo,
        "etag" | "last_modified" | "size" | "mime_type" | "type" | "is_favorite" | "is_shared"
      >
    >
): DriveFileInfo {
  return {
    ...partial,
    etag: partial.etag ?? `"demo-${partial.path}"`,
    last_modified: partial.last_modified ?? demoNow(),
    size: partial.size ?? 0,
    mime_type: partial.mime_type ?? "application/octet-stream",
    type: partial.type ?? "file",
    is_favorite: partial.is_favorite ?? false,
    is_shared: partial.is_shared ?? false,
  }
}

/** Flat demo file tree (paths like Nextcloud). */
export const DEMO_DRIVE_FILES: DriveFileInfo[] = [
  // — Dossiers —
  file({
    path: "/Produit",
    name: "Produit",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 101,
    last_modified: demoDaysAgo(14, 9, 0),
  }),
  file({
    path: "/Produit/Comités",
    name: "Comités",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 102,
    last_modified: demoDaysAgo(3, 16, 45),
  }),
  file({
    path: "/Marketing",
    name: "Marketing",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 103,
    last_modified: demoDaysAgo(10, 11, 20),
  }),
  file({
    path: "/Marketing/Campagne lancement",
    name: "Campagne lancement",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 104,
    last_modified: demoDaysAgo(6, 10, 0),
  }),
  file({
    path: "/RH",
    name: "RH",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 105,
    last_modified: demoDaysAgo(12, 8, 30),
  }),
  file({
    path: "/RH/Onboarding",
    name: "Onboarding",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 106,
    last_modified: demoDaysAgo(7, 14, 0),
  }),
  file({
    path: "/Perso",
    name: "Perso",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 107,
    last_modified: demoDaysAgo(11, 18, 15),
  }),
  file({
    path: "/Archives",
    name: "Archives",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 108,
    last_modified: demoDaysAgo(13, 9, 0),
  }),
  file({
    path: "/Archives/2025",
    name: "2025",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 109,
    last_modified: demoDaysAgo(13, 9, 5),
  }),
  file({
    path: "/Partagé",
    name: "Partagé",
    type: "directory",
    mime_type: "httpd/unix-directory",
    file_id: 110,
    last_modified: demoDaysAgo(4, 11, 30),
  }),

  // — Produit —
  file({
    path: "/Produit/Comité produit — CR 9 juin.ultidoc",
    name: "Comité produit — CR 9 juin.ultidoc",
    size: 287_400,
    mime_type: "application/vnd.ultimail.document",
    file_id: 111,
    source: "ultimail",
    is_favorite: true,
    last_modified: demoDaysAgo(0, 10, 15),
  }),
  file({
    path: "/Produit/Roadmap Q3.pdf",
    name: "Roadmap Q3.pdf",
    size: 1_842_000,
    mime_type: "application/pdf",
    file_id: 112,
    last_modified: demoDaysAgo(1, 15, 20),
  }),
  file({
    path: "/Produit/Specs fonctionnelles v2.4.ultidoc",
    name: "Specs fonctionnelles v2.4.ultidoc",
    size: 412_800,
    mime_type: "application/vnd.ultimail.document",
    file_id: 113,
    source: "ultimail",
    is_shared: true,
    last_modified: demoDaysAgo(2, 9, 40),
  }),
  file({
    path: "/Produit/Comités/Retro sprint 24 — notes.ultidoc",
    name: "Retro sprint 24 — notes.ultidoc",
    size: 156_200,
    mime_type: "application/vnd.ultimail.document",
    file_id: 114,
    source: "ultimail",
    last_modified: demoDaysAgo(3, 17, 10),
  }),

  // — Marketing —
  file({
    path: "/Marketing/Présentation lancement Q3.pptx",
    name: "Présentation lancement Q3.pptx",
    size: 5_640_000,
    mime_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    file_id: 115,
    last_modified: demoDaysAgo(1, 11, 0),
  }),
  file({
    path: "/Marketing/Bannière site — hero.png",
    name: "Bannière site — hero.png",
    size: 2_180_000,
    mime_type: "image/png",
    file_id: 116,
    last_modified: demoDaysAgo(4, 14, 30),
  }),
  file({
    path: "/Marketing/Charte graphique 2026.pdf",
    name: "Charte graphique 2026.pdf",
    size: 3_210_000,
    mime_type: "application/pdf",
    file_id: 117,
    is_favorite: true,
    last_modified: demoDaysAgo(5, 10, 45),
  }),
  file({
    path: "/Marketing/Campagne lancement/Brief créatif.docx",
    name: "Brief créatif.docx",
    size: 67_500,
    mime_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    file_id: 118,
    is_shared: true,
    last_modified: demoDaysAgo(6, 16, 20),
  }),

  // — RH —
  file({
    path: "/RH/Contrat type CDI.docx",
    name: "Contrat type CDI.docx",
    size: 48_300,
    mime_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    file_id: 119,
    last_modified: demoDaysAgo(8, 9, 15),
  }),
  file({
    path: "/RH/Guide télétravail.pdf",
    name: "Guide télétravail.pdf",
    size: 892_000,
    mime_type: "application/pdf",
    file_id: 120,
    last_modified: demoDaysAgo(9, 13, 0),
  }),
  file({
    path: "/RH/Onboarding/Checklist jour 1.ultidoc",
    name: "Checklist jour 1.ultidoc",
    size: 94_600,
    mime_type: "application/vnd.ultimail.document",
    file_id: 121,
    source: "ultimail",
    last_modified: demoDaysAgo(7, 8, 50),
  }),

  // — Perso —
  file({
    path: "/Perso/Notes réunion.txt",
    name: "Notes réunion.txt",
    size: 4_200,
    mime_type: "text/plain",
    file_id: 122,
    last_modified: demoDaysAgo(2, 18, 30),
  }),
  file({
    path: "/Perso/Idées side project.ultidoc",
    name: "Idées side project.ultidoc",
    size: 38_900,
    mime_type: "application/vnd.ultimail.document",
    file_id: 123,
    source: "ultimail",
    last_modified: demoDaysAgo(10, 20, 0),
  }),
  file({
    path: "/Perso/Photo équipe offsite.jpg",
    name: "Photo équipe offsite.jpg",
    size: 3_450_000,
    mime_type: "image/jpeg",
    file_id: 124,
    last_modified: demoDaysAgo(11, 19, 45),
  }),

  // — Archives —
  file({
    path: "/Archives/CR comité — mai.ultidoc",
    name: "CR comité — mai.ultidoc",
    size: 221_000,
    mime_type: "application/vnd.ultimail.document",
    file_id: 125,
    source: "ultimail",
    last_modified: demoDaysAgo(12, 10, 0),
  }),
  file({
    path: "/Archives/2025/Budget 2025.xlsx",
    name: "Budget 2025.xlsx",
    size: 76_800,
    mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    file_id: 126,
    last_modified: demoDaysAgo(13, 9, 30),
  }),

  // — Partagé (dossier local) —
  file({
    path: "/Partagé/Analyse concurrence.xlsx",
    name: "Analyse concurrence.xlsx",
    size: 112_400,
    mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    file_id: 127,
    is_shared: true,
    last_modified: demoDaysAgo(3, 11, 15),
  }),

  // — Racine —
  file({
    path: "/Budget 2026.xlsx",
    name: "Budget 2026.xlsx",
    size: 89_000,
    mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    file_id: 128,
    is_favorite: true,
    last_modified: demoDaysAgo(0, 8, 0),
  }),
  file({
    path: "/Logo Ultimail.svg",
    name: "Logo Ultimail.svg",
    size: 12_400,
    mime_type: "image/svg+xml",
    file_id: 129,
    last_modified: demoDaysAgo(14, 10, 0),
  }),
  file({
    path: "/Architecture système — schéma.svg",
    name: "Architecture système — schéma.svg",
    size: 18_700,
    mime_type: "image/svg+xml",
    file_id: 130,
    last_modified: demoDaysAgo(5, 15, 30),
  }),
  file({
    path: "/Release notes v2.3.txt",
    name: "Release notes v2.3.txt",
    size: 8_900,
    mime_type: "text/plain",
    file_id: 131,
    last_modified: demoDaysAgo(1, 9, 30),
  }),
]

export const DEMO_DRIVE_RECENT_IDS = [111, 128, 131, 112, 115, 113, 122, 127]
export const DEMO_DRIVE_STARRED_IDS = [111, 117, 128]

export const DEMO_DRIVE_TRASH: DriveFileInfo[] = [
  file({
    path: "/Ancien brief.docx",
    name: "Ancien brief.docx",
    size: 34_000,
    mime_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    file_id: 201,
    last_modified: demoDaysAgo(5, 16, 0),
  }),
  file({
    path: "/Export contacts — test.csv",
    name: "Export contacts — test.csv",
    size: 12_800,
    mime_type: "text/csv",
    file_id: 202,
    last_modified: demoDaysAgo(8, 11, 45),
  }),
  file({
    path: "/Maquette homepage v1.pptx",
    name: "Maquette homepage v1.pptx",
    size: 4_120_000,
    mime_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    file_id: 203,
    last_modified: demoDaysAgo(11, 14, 20),
  }),
]

export const DEMO_DRIVE_SHARED: DriveFileInfo[] = [
  file({
    path: "/Partagé/Specs API v2.pdf",
    name: "Specs API v2.pdf",
    size: 512_000,
    mime_type: "application/pdf",
    file_id: 301,
    is_shared: true,
    last_modified: demoDaysAgo(0, 14, 0),
  }),
  file({
    path: "/Partagé/Benchmark SaaS européens.xlsx",
    name: "Benchmark SaaS européens.xlsx",
    size: 98_600,
    mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    file_id: 302,
    is_shared: true,
    last_modified: demoDaysAgo(2, 10, 30),
  }),
  file({
    path: "/Partagé/CR réunion client — Delcourt.pdf",
    name: "CR réunion client — Delcourt.pdf",
    size: 245_000,
    mime_type: "application/pdf",
    file_id: 303,
    is_shared: true,
    last_modified: demoDaysAgo(4, 17, 45),
  }),
  file({
    path: "/Partagé/Wireframes flux auth.ultidoc",
    name: "Wireframes flux auth.ultidoc",
    size: 178_300,
    mime_type: "application/vnd.ultimail.document",
    file_id: 304,
    source: "ultimail",
    is_shared: true,
    last_modified: demoDaysAgo(1, 13, 15),
  }),
]
