import type { TguPlanUi, TguPlatformUi, TimelineRange } from "../../../model/timelineTypes";

export type EditorWorkKind = "shoot" | "downlink";

export type EditorWorkOrigin = "plan" | "added";

export type EditorWorkBase = {
  id: string;
  kind: EditorWorkKind;
  label: string;
  startMs: number;
  endMs: number;
  origin: EditorWorkOrigin;
  isNew?: boolean;
};

export type EditorShootWork = EditorWorkBase & {
  kind: "shoot";
  modeId?: string;
  targetName?: string;
  targetLat?: number;
  targetLon?: number;
};

export type EditorDownlinkWork = EditorWorkBase & {
  kind: "downlink";
  stationId?: string;
};

export type EditorWork = EditorShootWork | EditorDownlinkWork;

export type EditorWorkPatch =
  Partial<Omit<EditorWorkBase, "id" | "kind">> &
  Partial<Pick<EditorShootWork, "modeId" | "targetLat" | "targetLon" | "targetName">> &
  Partial<Pick<EditorDownlinkWork, "stationId">>;

export type Draft = {
  planId?: string;
  spacecraftId?: string;
  works: EditorWork[];
};

export type DraftHistory = {
  draft: Draft;
  past: Draft[];
  future: Draft[];
};

export type EditorTarget = {
  id: string;
  name: string;
  lat: number;
  lon: number;
};

export type EditorGroundStation = {
  id: string;
  name: string;
  lat?: number;
  lon?: number;
};

export type EditorVisibilityWindow = {
  startMs: number;
  endMs: number;
  quality: number;
};

export type EditorVisibilityTrack = {
  id: string;
  label: string;
  kind: "target" | "station";
  color: string;
  windows: EditorVisibilityWindow[];
};

export type EditorTimelineWindow = {
  fromMs: number;
  toMs: number;
};

export type EditorContextLane = {
  spacecraftId: string;
  label: string;
  works: EditorWork[];
};

export type EditorMode = {
  id: string;
  label: string;
};

export type EditorCheckContext = {
  spacecraftId?: string;
  stations: EditorGroundStation[];
  marginMs?: number;
};

export type TguEditorTabProps = {
  selectedSpacecraftId?: string;
  selectedPlan?: TguPlanUi;
  appliedRange: TimelineRange;
  platforms: TguPlatformUi[];
};
