import { GeoChartRegion } from "./chart/geo_chart";
import { Client, ClientPosition } from "./collaborative/session";
import { TransportService } from "./collaborative/transport_service";
import { Currency } from "./currency";
import { FileStore } from "./files";
import { Locale } from "./locale";
import { Color } from "./misc";
import { ColorThemeName } from "./rendering";

export type Mode = "normal" | "readonly" | "dashboard" | "export_verification";

export interface ModelConfig {
  readonly mode: Mode;
  /**
   * Any external custom dependencies your custom plugins or functions might need.
   * They are available in plugins config and functions
   * evaluation context.
   */
  readonly custom: Readonly<{
    [key: string]: any;
  }>;
  readonly defaultCurrency?: Partial<Currency>;
  /**
   * External dependencies required to enable some features
   * such as uploading images.
   */
  readonly external: Readonly<ModelExternalConfig>;
  readonly moveClient: (position: ClientPosition) => void;
  readonly transportService: TransportService;
  readonly client: Client;
  readonly snapshotRequested: boolean;
  readonly customColors: Color[];
  readonly colorScheme?: ColorThemeName;
}

export interface ModelExternalConfig {
  readonly fileStore?: FileStore;
  readonly loadCurrencies?: () => Promise<Currency[]>;
  readonly loadLocales?: () => Promise<Locale[]>;
  readonly geoJsonService?: {
    getAvailableRegions: () => GeoChartRegion[];
    getTopoJson: (region: string) => Promise<any>;
    /**  Convert the name of a geographical feature (eg. France) to the id of the corresponding feature in the TopoJSON */
    geoFeatureNameToId: (region: string, territory: string) => string | undefined;
    isRegionAvailable: (region: string) => boolean;
    /** Returns the regions that can be selected as an alternative when the chart was initially configured with the given region */
    getAlternativeRegions?: (region: string) => GeoChartRegion[];
  };
}
