"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/services/delegates/gsuite/scheduleMeeting.ts
var scheduleMeeting_exports = {};
__export(scheduleMeeting_exports, {
  scheduleMeeting: () => scheduleMeeting
});
module.exports = __toCommonJS(scheduleMeeting_exports);
var import_crypto = require("crypto");
var LOG_PREFIX = "GSUITE - scheduleMeeting - ";
function validateScheduleMeetingInput(context) {
  const { summary, start, end, attendees } = context;
  if (!summary || typeof summary !== "string") {
    throw new Error("Summary is required and must be a string");
  }
  if (!start || !Date.parse(start)) {
    throw new Error("Valid start time is required");
  }
  if (!end || !Date.parse(end)) {
    throw new Error("Valid end time is required");
  }
  if (!attendees || !Array.isArray(attendees) || attendees.length === 0) {
    throw new Error("At least one attendee is required");
  }
}
async function scheduleMeeting(calendar, context) {
  console.log(`${LOG_PREFIX} Processing meeting request:
  summary: ${context.summary}
  attendees: ${JSON.stringify(context.attendees, null, 2)}`);
  validateScheduleMeetingInput(context);
  const event = {
    summary: context.summary,
    description: context.description,
    start: { dateTime: context.start },
    end: { dateTime: context.end },
    attendees: context.attendees.map((email) => ({ email })),
    conferenceData: {
      createRequest: {
        requestId: (0, import_crypto.randomUUID)(),
        conferenceSolutionKey: { type: "hangoutsMeet" }
      }
    }
  };
  const { data } = await calendar.events.insert({
    calendarId: "primary",
    requestBody: event,
    sendUpdates: "all",
    conferenceDataVersion: 1
  });
  const meetLink = data.hangoutLink ?? data.conferenceData?.entryPoints?.find((e) => e.entryPointType === "video")?.uri;
  if (!data.id || !meetLink) {
    throw new Error("Google Calendar did not return a Meet link");
  }
  console.log(`${LOG_PREFIX} Meeting Created:
  calendar returned: ${JSON.stringify({
    id: data.id,
    htmlLink: data.htmlLink,
    status: data.status
  }, null, 2)}`);
  return {
    id: data.id,
    htmlLink: data.htmlLink,
    status: data.status
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  scheduleMeeting
});
