import { OnlineTypeEnum } from 'src/common/enum/online-type.enum';
import { SessionLaunchMode } from 'src/common/enum/session-launch-mode.enum';
import { RegistrationOnlineSessionActivationStatus } from 'src/common/enum/registration-online-session-activation-status.enum';

/** Minimal registration fields needed to resolve its online sessions, join URLs and attendance. */
export interface RegistrationLike {
  id: number;
  programId?: number | null;
  userId?: number | null;
  emailAddress?: string | null;
  mobileNumber?: string | null;
  /** Whether this registration holds an allocated seat — required for {@link RegistrationSessionInfoService.isEligibleToJoin}. */
  seatAllocated?: boolean | null;
  /** Registration-level activation rollup — required for {@link RegistrationSessionInfoService.isEligibleToJoin}. */
  activationStatus?: RegistrationOnlineSessionActivationStatus | null;
}

/**
 * Contact identity of the logged-in user a registration list is being built for.
 * When provided, a registration's joinUrl is only surfaced if it matches this
 * contact (email, case-insensitive, or mobile) — a proxy registration made by
 * this user on someone else's behalf should not leak that person's join link.
 */
export interface RegistrationViewerContact {
  emailAddress?: string | null;
  mobileNumber?: string | null;
}

/** Per-session attendance for a registrant, with a flag per source. */
export interface RegistrationSessionAttendance {
  isAttended: boolean;
  checkedInAt: Date | null;
  /** Attended by clicking the in-app join link. */
  viaJoinClick: boolean;
  /** Attended per a Zoom participant-joined webhook. */
  viaZoom: boolean;
  /** Marked attended by an admin. */
  viaManual: boolean;
}

/** One online session of a registration's program, with the registrant's join + attendance state. */
export interface RegistrationOnlineSessionInfo {
  sessionId: number;
  sessionName: string | null;
  onlineType: OnlineTypeEnum | null;
  startsAt: Date | null;
  endsAt: Date | null;
  launchMode: SessionLaunchMode;
  providerType: string | null;
  /** Whether the provider resource (Zoom meeting/webinar) is provisioned. */
  provisioned: boolean;
  /** External provider id of the provisioned resource (Zoom meetingId / webinarId); null when not yet provisioned. */
  webinarId: string | null;
  /** The registrant's join URL (per-registrant link, falling back to the shared session link). */
  joinUrl: string | null;
  isPanelist: boolean;
  /**
   * Registration-level eligibility to see any join action at all — see
   * {@link RegistrationSessionInfoService.isEligibleToJoin} for the full rule
   * (seat allocated, activation status ACTIVE, and the viewer's own contact
   * matching this registration when a viewer contact was given).
   */
  eligibleToJoin: boolean;
  /** True only inside the join window AND when a join URL exists. Does not account for `eligibleToJoin` — check both. */
  joinEnabled: boolean;
  joinOpensAt: Date | null;
  joinClosesAt: Date | null;
  /**
   * How many minutes before `startsAt` the join window opens — the effective value the join
   * window is computed from (`joinOpensMinutesBefore`, falling back to the platform default).
   * `joinOpensAt` is the resulting absolute time; this is the configured lead time itself.
   */
  preSessionJoiningTime: number;
  attendance: RegistrationSessionAttendance;
}
