// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
//
// SPDX-License-Identifier: GPL-2.0-or-later

import type { SatelliteScheduleConfig, SatelliteSchedulerApi } from "./satellite-types.js";

export type SchedulerMode = "disabled" | "grayline" | "time_span";

export interface SchedulerBookmark {
  id: string;
  name: string;
  freq_hz: number;
  mode: string;
}

export interface GraylineConfig {
  lat: number;
  lon: number;
  transition_window_min: number;
  day_bookmark_id: string | null;
  night_bookmark_id: string | null;
  dawn_bookmark_id: string | null;
  dusk_bookmark_id: string | null;
}

export interface ScheduleEntry {
  id?: string;
  start_min: number;
  end_min: number;
  bookmark_id: string;
  label: string | null;
  interleave_min: number | null;
  center_hz: number | null;
  bookmark_ids: string[];
  record: boolean;
  exclusive?: boolean;
}

export interface SchedulerConfig {
  remote: string | null;
  mode: SchedulerMode;
  grayline: GraylineConfig | null;
  entries: ScheduleEntry[];
  interleave_min?: number | null;
  satellites?: SatelliteScheduleConfig | null;
}

export interface SchedulerStatus {
  active: boolean;
  last_entry_id?: string | null;
  last_bookmark_id?: string | null;
  last_bookmark_name?: string | null;
  last_applied_utc?: number | null;
  last_center_hz?: number | null;
  last_bookmark_ids?: string[];
  active_satellite?: string | null;
  freq_hz?: number | null;
  mode?: string | null;
  active_decoders?: string[];
}

export interface SchedulerService {
  initialize(rigId: string | null, role: string | null): void;
  destroy(): void;
  setRig(rigId: string | null): void;
  wireEvents(): void;
  getConfig(): SchedulerConfig | null;
  getStatus(): SchedulerStatus | null;
  getBookmarks(): SchedulerBookmark[];
  markDirty(): void;
}
interface VirtualChannelService {
  takeSchedulerControl(): Promise<void>;
  releaseToScheduler(): Promise<void>;
}

export interface SchedulerWindow {
  trx: { modules: { scheduler?: SchedulerService; vchan?: VirtualChannelService } };
  trxUi: {
    confirm(options: { title: string; message: string; confirmLabel: string; danger?: boolean }): Promise<boolean>;
    notify?(message: string, options: { kind: "error" }): void;
  };
  satScheduler?: SatelliteSchedulerApi;
}
