import { OnlineTypeEnum } from '../enum/online-type.enum';
import { SessionProviderType } from '../enum/session-provider.enum';
import { ZoomWebinarStatus } from '../enum/zoom-webinar-status.enum';
import { SessionLaunchMode } from '../enum/session-launch-mode.enum';
import { SessionLinkModeEnum } from '../enum/session-link-mode.enum';

/**
 * Provider-neutral payloads exchanged between the online-session orchestrator
 * and any provider. Provider-specific shapes (Zoom REST bodies/responses) never
 * cross this boundary — each provider maps to/from these at its own edge.
 */

/** Neutral input for creating an online session. */
export interface CreateSessionInput {
  provider: SessionProviderType;
  onlineType: OnlineTypeEnum.WEBINAR | OnlineTypeEnum.MEETING;
  programSessionId: number;
  title?: string;
  startAt: string;
  duration: number;
  password?: string;
  hostEmail?: string;
  /** Meetings only — per-user registrants vs a single shared join link. */
  requireRegistration?: boolean;
  /** Where attendees launch from (embedded SDK vs Zoom client). */
  launchMode?: SessionLaunchMode;
  /** Minutes before start the join link opens (null/undefined → default). */
  joinOpensMinutesBefore?: number;
  /** Minutes before start the host/admin can start the session (store-only; FE gates). */
  hostStartOpensMinutesBefore?: number;
  /** Initial lifecycle status; defaults to DRAFT when omitted. */
  status?: ZoomWebinarStatus;
  registrationStartsAt?: string;
  registrationEndsAt?: string;
  /** Audit — the acting user id. */
  actorUserId?: number;
}

/**
 * Provider-neutral recurrence rule for a shared ("same link") webinar. Mapped to
 * the provider's own recurrence shape at its edge (Zoom: `recurrence`).
 */
export interface SessionRecurrenceInput {
  /** daily | weekly | monthly. */
  frequency: 'daily' | 'weekly' | 'monthly';
  repeatInterval?: number;
  /** Weekly only: comma-separated weekday numbers (Zoom: 1=Sun … 7=Sat, e.g. '2,3,4'). */
  weeklyDays?: string;
  // Note: the occurrence COUNT is always forced to the number of sessions (each
  // occurrence is pinned to a real session date), so there is no end-times /
  // end-date field — it could only disagree with the session list.
}

/**
 * Neutral input to provision ONE recurring webinar shared across several program
 * sessions ("same link"): one external resource, one join link per registrant
 * valid for every session. The provider creates a single recurring webinar and
 * writes one online-session row per program session, all sharing its external id.
 */
export interface CreateSharedSessionInput {
  provider: SessionProviderType;
  /** Session type: webinar (default) or meeting. Both support the shared model. */
  onlineType?: OnlineTypeEnum.WEBINAR | OnlineTypeEnum.MEETING;
  /** Program sessions to back with the one shared resource (>= 2). */
  programSessionIds: number[];
  title?: string;
  password?: string;
  hostEmail?: string;
  /** Meetings only — per-user registrant links vs one shared link. Default true. */
  requireRegistration?: boolean;
  /**
   * `PER_SESSION` ("individual"): each session gets its own distinct,
   * non-recurring resource. `SHARED` ("group"): one recurring resource backs
   * every session with the same join link. Duration is derived per session from
   * `ProgramSession.startsAt`/`endsAt`, never caller-supplied.
   */
  linkType: SessionLinkModeEnum;
  launchMode?: SessionLaunchMode;
  joinOpensMinutesBefore?: number;
  hostStartOpensMinutesBefore?: number;
  status?: ZoomWebinarStatus;
  /**
   * Recurrence rule for the webinar. When omitted, the provider derives a weekly
   * rule from the distinct weekdays of the target sessions (occurrence count =
   * number of sessions).
   */
  recurrence?: SessionRecurrenceInput;
  actorUserId?: number;
}

/** Neutral input for updating an online session; only provided fields change. */
export interface UpdateSessionInput {
  title?: string;
  startAt?: string;
  duration?: number;
  password?: string;
  launchMode?: SessionLaunchMode;
  joinOpensMinutesBefore?: number;
  hostStartOpensMinutesBefore?: number;
  registrationStartsAt?: string;
  registrationEndsAt?: string;
  actorUserId?: number;
  /** Manual lifecycle override; normally status is webhook-driven. */
  status?: ZoomWebinarStatus;
}

/** Neutral attendance/analytics row returned by a provider. */
export interface ParticipantData {
  extParticipantId: string | null;
  name: string | null;
  email: string | null;
  joinedAt: Date | null;
  leftAt: Date | null;
  durationSeconds: number;
}
