import { addDays, addHours, addMinutes, setHours, setMinutes, startOfDay } from "date-fns"
import type { AgendaApiEvent, AgendaCalendar } from "@/lib/agenda/agenda-types"
import { formatICSDateOnly, formatICSDateTimeUTC } from "@/lib/agenda/agenda-date"

export const DEMO_AGENDA_CALENDARS: AgendaCalendar[] = [
  {
    id: "personal",
    display_name: "Camille Visiteur",
    color: "#039be5",
    path: "/calendars/personal",
  },
  {
    id: "work",
    display_name: "Produit",
    color: "#4f6df5",
    path: "/calendars/work",
  },
]

const WORK_COLOR = "#4f6df5"
const PERSONAL_COLOR = "#039be5"

function at(dayOffset: number, hour: number, minute = 0): Date {
  const base = startOfDay(new Date())
  return setMinutes(setHours(addDays(base, dayOffset), hour), minute)
}

export function createInitialDemoAgendaEvents(): AgendaApiEvent[] {
  const standupStart = at(0, 9, 30)
  const oneOnOneStart = at(0, 10, 45)
  const lunchStart = at(0, 12, 30)
  const clientCallStart = at(0, 15, 0)
  const sprintReviewStart = at(1, 16, 30)
  const doctorStart = at(2, 8, 30)
  const roadmapStart = at(2, 14, 0)
  const workshopStart = at(3, 10, 0)
  const infraStart = at(3, 14, 0)
  const internalDemoStart = at(4, 11, 0)
  const focusDay = at(4, 0, 0)
  const runStart = at(5, 7, 0)
  const betaDeadlineStart = at(5, 17, 0)
  const offsiteDay = at(6, 0, 0)
  const retroStart = at(6, 14, 0)

  return [
    {
      uid: "demo-standup",
      summary: "Stand-up équipe produit",
      description: "Point quotidien — avancement sprint, blocages, démo interactive.",
      location: "UltiMeet",
      start: formatICSDateTimeUTC(standupStart),
      end: formatICSDateTimeUTC(addHours(standupStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-standup.ics",
      etag: '"demo-standup"',
      organizer: "lea.fontaine@atelier-nord.fr",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
        { email: "thomas.giraud@proton.me", name: "Thomas Giraud", status: "ACCEPTED" },
        { email: "julien.carpentier@proton.me", name: "Julien Carpentier", status: "TENTATIVE" },
      ],
      meet_url: "https://meet.demo.ulti/standup",
      color: WORK_COLOR,
    },
    {
      uid: "demo-one-on-one",
      summary: "1-on-1 — Léa Fontaine",
      description: "Suivi carrière, feedback sur la refonte agenda.",
      location: "Salle Boreal",
      start: formatICSDateTimeUTC(oneOnOneStart),
      end: formatICSDateTimeUTC(addMinutes(oneOnOneStart, 30)),
      all_day: false,
      path: "/calendars/work/demo-one-on-one.ics",
      etag: '"demo-one-on-one"',
      organizer: "lea.fontaine@atelier-nord.fr",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
      ],
      color: WORK_COLOR,
    },
    {
      uid: "demo-lunch",
      summary: "Déjeuner équipe design",
      description: "Célébrer la livraison du nouveau parcours onboarding.",
      location: "Le Comptoir, 12 rue de la Paix, Paris 2e",
      start: formatICSDateTimeUTC(lunchStart),
      end: formatICSDateTimeUTC(addHours(lunchStart, 1)),
      all_day: false,
      path: "/calendars/personal/demo-lunch.ics",
      etag: '"demo-lunch"',
      organizer: "camille@demo.ulti",
      attendees: [
        { email: "marie.deschamps@yahoo.fr", name: "Marie Deschamps", status: "ACCEPTED" },
        { email: "damien.girard@gmail.com", name: "Damien Girard", status: "NEEDS-ACTION" },
      ],
      color: PERSONAL_COLOR,
    },
    {
      uid: "demo-client-call",
      summary: "Appel client — Atelier Nord",
      description: "Présentation Ultimail Agenda + intégration UltiMeet pour leur équipe.",
      location: "UltiMeet",
      start: formatICSDateTimeUTC(clientCallStart),
      end: formatICSDateTimeUTC(addHours(clientCallStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-client-call.ics",
      etag: '"demo-client-call"',
      organizer: "camille@demo.ulti",
      attendees: [
        { email: "lea.fontaine@atelier-nord.fr", name: "Léa Fontaine", status: "ACCEPTED" },
        { email: "vincent.morel@gmail.com", name: "Vincent Morel", status: "TENTATIVE" },
      ],
      meet_url: "https://meet.demo.ulti/atelier-nord",
      color: WORK_COLOR,
    },
    {
      uid: "demo-sprint-review",
      summary: "Revue de sprint",
      description: "Démo des stories livrées — focus calendrier partagé et invitations mail.",
      location: "Salle Atlas",
      start: formatICSDateTimeUTC(sprintReviewStart),
      end: formatICSDateTimeUTC(addHours(sprintReviewStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-sprint-review.ics",
      etag: '"demo-sprint-review"',
      organizer: "lea.fontaine@atelier-nord.fr",
      attendees: [
        { email: "thomas.giraud@proton.me", name: "Thomas Giraud", status: "ACCEPTED" },
        { email: "julien.carpentier@proton.me", name: "Julien Carpentier", status: "NEEDS-ACTION" },
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
      ],
      meet_url: "https://meet.demo.ulti/sprint-review",
      color: WORK_COLOR,
    },
    {
      uid: "demo-doctor",
      summary: "RDV médecin",
      description: "Visite annuelle — bloquer la matinée en conséquence.",
      location: "Cabinet Dr. Martin, 8 av. de l'Opéra, Paris 1er",
      start: formatICSDateTimeUTC(doctorStart),
      end: formatICSDateTimeUTC(addMinutes(doctorStart, 30)),
      all_day: false,
      path: "/calendars/personal/demo-doctor.ics",
      etag: '"demo-doctor"',
      color: PERSONAL_COLOR,
    },
    {
      uid: "demo-review",
      summary: "Revue roadmap Q3",
      description: "Prioriser les chantiers agenda, drive et meet avant le comité.",
      location: "Salle Atlas",
      start: formatICSDateTimeUTC(roadmapStart),
      end: formatICSDateTimeUTC(addHours(roadmapStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-review.ics",
      etag: '"demo-review"',
      organizer: "vincent.morel@gmail.com",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
        { email: "lea.fontaine@atelier-nord.fr", name: "Léa Fontaine", status: "TENTATIVE" },
      ],
      color: WORK_COLOR,
    },
    {
      uid: "demo-workshop",
      summary: "Atelier design system — composants agenda",
      description: "Session collaborative : chips événements, drag & drop, popover invités.",
      location: "Open space Produit",
      start: formatICSDateTimeUTC(workshopStart),
      end: formatICSDateTimeUTC(addHours(workshopStart, 2)),
      all_day: false,
      path: "/calendars/work/demo-workshop.ics",
      etag: '"demo-workshop"',
      organizer: "damien.girard@gmail.com",
      attendees: [
        { email: "marie.deschamps@yahoo.fr", name: "Marie Deschamps", status: "ACCEPTED" },
        { email: "thomas.giraud@proton.me", name: "Thomas Giraud", status: "ACCEPTED" },
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "NEEDS-ACTION" },
      ],
      meet_url: "https://meet.demo.ulti/design-system",
      color: WORK_COLOR,
    },
    {
      uid: "demo-infra",
      summary: "Point infra & sécurité",
      description: "Revue des accès CalDAV, tokens API agenda et webhooks.",
      location: "UltiMeet",
      start: formatICSDateTimeUTC(infraStart),
      end: formatICSDateTimeUTC(addHours(infraStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-infra.ics",
      etag: '"demo-infra"',
      organizer: "guillaume.perrot@proton.me",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
        { email: "julien.carpentier@proton.me", name: "Julien Carpentier", status: "TENTATIVE" },
      ],
      meet_url: "https://meet.demo.ulti/infra",
      color: WORK_COLOR,
    },
    {
      uid: "demo-internal-demo",
      summary: "Démo interne Ultimail",
      description: "Présentation landing page + parcours démo mail, agenda et drive.",
      location: "Salle Polaris",
      start: formatICSDateTimeUTC(internalDemoStart),
      end: formatICSDateTimeUTC(addHours(internalDemoStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-internal-demo.ics",
      etag: '"demo-internal-demo"',
      organizer: "camille@demo.ulti",
      attendees: [
        { email: "lea.fontaine@atelier-nord.fr", name: "Léa Fontaine", status: "ACCEPTED" },
        { email: "vincent.morel@gmail.com", name: "Vincent Morel", status: "ACCEPTED" },
        { email: "thomas.giraud@proton.me", name: "Thomas Giraud", status: "NEEDS-ACTION" },
      ],
      meet_url: "https://meet.demo.ulti/demo-interne",
      color: WORK_COLOR,
    },
    {
      uid: "demo-focus",
      summary: "Focus — zéro interruption",
      description: "Journée sans réunion pour finaliser les specs agenda.",
      location: "",
      start: formatICSDateOnly(focusDay),
      end: formatICSDateOnly(addDays(focusDay, 1)),
      all_day: true,
      path: "/calendars/personal/demo-focus.ics",
      etag: '"demo-focus"',
      color: PERSONAL_COLOR,
    },
    {
      uid: "demo-run",
      summary: "Course — running club",
      description: "Sortie matinale avant la deadline beta.",
      location: "Bois de Vincennes, porte Dorée",
      start: formatICSDateTimeUTC(runStart),
      end: formatICSDateTimeUTC(addMinutes(runStart, 30)),
      all_day: false,
      path: "/calendars/personal/demo-run.ics",
      etag: '"demo-run"',
      color: PERSONAL_COLOR,
    },
    {
      uid: "demo-beta-deadline",
      summary: "Deadline — livraison beta agenda",
      description: "Gel des features, QA finale et préparation release notes.",
      location: "Salle Polaris",
      start: formatICSDateTimeUTC(betaDeadlineStart),
      end: formatICSDateTimeUTC(addHours(betaDeadlineStart, 1)),
      all_day: false,
      path: "/calendars/work/demo-beta-deadline.ics",
      etag: '"demo-beta-deadline"',
      organizer: "lea.fontaine@atelier-nord.fr",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
        { email: "thomas.giraud@proton.me", name: "Thomas Giraud", status: "ACCEPTED" },
      ],
      color: WORK_COLOR,
    },
    {
      uid: "demo-offsite",
      summary: "Offsite équipe produit",
      description: "Journée stratégie Q3 — vision suite souveraine et roadmap intégrée.",
      location: "Château de Chantilly, salle des Gardes",
      start: formatICSDateOnly(offsiteDay),
      end: formatICSDateOnly(addDays(offsiteDay, 1)),
      all_day: true,
      path: "/calendars/work/demo-offsite.ics",
      etag: '"demo-offsite"',
      organizer: "vincent.morel@gmail.com",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
        { email: "lea.fontaine@atelier-nord.fr", name: "Léa Fontaine", status: "ACCEPTED" },
        { email: "thomas.giraud@proton.me", name: "Thomas Giraud", status: "TENTATIVE" },
        { email: "julien.carpentier@proton.me", name: "Julien Carpentier", status: "NEEDS-ACTION" },
      ],
      color: WORK_COLOR,
    },
    {
      uid: "demo-retro",
      summary: "Rétrospective sprint",
      description: "Bilan du cycle — ce qui a bien fonctionné sur l'agenda démo.",
      location: "Salle Atlas",
      start: formatICSDateTimeUTC(retroStart),
      end: formatICSDateTimeUTC(addHours(retroStart, 2)),
      all_day: false,
      path: "/calendars/work/demo-retro.ics",
      etag: '"demo-retro"',
      organizer: "lea.fontaine@atelier-nord.fr",
      attendees: [
        { email: "camille@demo.ulti", name: "Camille Visiteur", status: "ACCEPTED" },
        { email: "marie.deschamps@yahoo.fr", name: "Marie Deschamps", status: "ACCEPTED" },
        { email: "damien.girard@gmail.com", name: "Damien Girard", status: "NEEDS-ACTION" },
      ],
      meet_url: "https://meet.demo.ulti/retro",
      color: WORK_COLOR,
    },
  ]
}
