import type { ApiClient } from "./client.js";

export interface AppSettingsFilterOptions {
  searchFrom?: string;
  searchTo?: string;
  timeStep?: string;
}

export interface AppSettingsButtonsBuyTicketPeriod {
  min?: string;
  max?: string;
}

export interface AppSettingsButtonsBuyTicket {
  period?: AppSettingsButtonsBuyTicketPeriod;
}

export interface AppSettingsButtonsFlightStatus {
  availableFrom?: string;
  visible?: string;
}

export interface AppSettingsButtons {
  flightStatus?: AppSettingsButtonsFlightStatus;
  buyTicket?: AppSettingsButtonsBuyTicket;
}

export interface AppSettingsResponse {
  showDebugVersion?: string;
  uiOptions?: {
    isTestVersion?: string;
    filter?: {
      onlineboard?: AppSettingsFilterOptions;
      schedule?: AppSettingsFilterOptions;
    };
    buttons?: AppSettingsButtons;
  };
}

/**
 * Fetch the global UI configuration from the backend. Includes date range
 * limits for online-board and schedule searches.
 */
export async function getAppSettings(client: ApiClient): Promise<AppSettingsResponse> {
  return client.get<AppSettingsResponse>("/appSettings");
}
