import {
  JIBESTREAM_DESTINATION,
  INSTRUCTION,
  JIBESTREAM_WAYPOINT,
  JIBESTREAM_PATH,
  JIBESTREAM_STYLE,
  MAP_CREDENTIALS,
  MAP_COMPASS_PROPERTIES,
  MAP_FLOOR_SELECTOR_PROPERTIES,
  MAP_SEARCH_PROPERTIES,
  MAP_ZOOM_BUTTON_PROPERTIES,
  GEOJSON_PATH,
  JIBESTREAM_GEOFENCE,
  SIMULATION_OPTIONS,
  SIMULATION_STATUS,
  SIMULATION_PATH,
} from './JibestreamTypes';
import { ODP_ON_FACILITY_UPDATE } from './schemas/OdpOnFacilityUpdateType';
import { ODP_ON_KEY_VALIDATION } from './schemas/OdpOnKeyValidationType';
import { ODP_ON_NAVIGATION_UPDATE } from './schemas/OdpOnNavigationUpdateType';
import { ODP_ON_READY } from './schemas/OdpOnReadyType';

export type COMMANDS_FROM_MAP =
  | 'DESTINATION_SELECTED'
  | 'NAVIGATION_PATH_GENERATED'
  | 'REROUTE_NAVIGATION_PATH_GENERATED'
  | 'USER_POSITION_UPDATED'
  | 'WINDOW_LOADED'
  | 'MAP_TAPPED_GENERIC'
  | 'GENERATED_SEARCH_DESTINATIONS'
  | 'TESTING'
  | 'ERROR'
  | 'GEOFENCES_CHANGED'
  | 'VENUE_LOADED';
export type EVENTS_FROM_ODP =
  | 'ODP_ON_READY'
  | 'ODP_ON_KEY_VALIDATION'
  | 'ON_NAVIGATION_UPDATE'
  | 'ON_FACILITY_UPDATE';
export type MAP_LOCALE = 'en-US' | 'es-ES';
export type DISTANCE_UNIT = 'METERS' | 'FEET' | 'INCHES';
export type COORDINATE_TYPE = 'LAT_LONG' | 'X_Y';
export type SIMULATION_COMMAND = 'PLAY' | 'PAUSE' | 'STOP';

export type MAP_EVENT_LISTENER = {
  onDestinationSelected?: (destination: JIBESTREAM_DESTINATION) => void;
  onNavigationPathGenerated?: (
    pathId: string,
    instructions: INSTRUCTION[],
    start: JIBESTREAM_WAYPOINT,
    end: JIBESTREAM_WAYPOINT,
    jibestreamPath: JIBESTREAM_PATH[],
    path: GEOJSON_PATH
  ) => void;
  onRerouteNavigationPathGenerated?: (
    pathId: string,
    instructions: INSTRUCTION[],
    start: JIBESTREAM_WAYPOINT,
    end: JIBESTREAM_WAYPOINT,
    jibestreamPath: JIBESTREAM_PATH[],
    path: GEOJSON_PATH
  ) => void;
  onUserPositionUpdated?: (userPosition: number[]) => void;
  onSearchDestinationsGenerated?: (
    destinations: JIBESTREAM_DESTINATION[]
  ) => void;
  onWindowLoaded?: () => void;
  onError?: (msg: string) => void;
  onVenueLoaded?: (venueId: number) => void;
  onMapTappedGeneric?: (event: MAP_TAP_EVENT) => void;
  onGeofencesChanged?: (
    entered: boolean,
    geofences: JIBESTREAM_GEOFENCE[]
  ) => void;
  onSimulationStatusChanged?: (status: SIMULATION_STATUS) => void;
};

export type ODP_EVENT_LISTENER = {
  onReady?: (message: ODP_ON_READY) => void;
  onKeyValidation?: (message: ODP_ON_KEY_VALIDATION) => void;
  onNavigationUpdate?: (message: ODP_ON_NAVIGATION_UPDATE) => void;
  onFacilityUpdate?: (message: ODP_ON_FACILITY_UPDATE) => void;
};

export type ODP_VIEW_REFERENCE = {
  startOdp: (key: string, host: string) => void;
  stopOdp: () => void;
  uploadLogs: () => void;
};

export type MAP_VIEW_REFERENCE = {
  setMapVenue: (credentials: MAP_CREDENTIALS, mapOptions?: MAP_OPTIONS) => void;
  centerMapOnUser: (
    orientation: number,
    zoom?: number,
    animationDuration?: number
  ) => void;
  //   centerMapOnPoint: (point: number[]) => void;
  setFollowBlueDot: (
    enabled: boolean,
    rotate?: boolean,
    interval?: number
  ) => void;
  setUserPosition: (
    lat: number,
    long: number,
    heading: number,
    confidence: number
  ) => void;
  setUserPositionXY: (
    x: number,
    y: number,
    heading: number,
    confidence
  ) => void;
  clearWayfindingPath: () => void;
  wayfindToWaypoint: (waypointId: number) => void;
  wayfindBetweenWaypoints: (originId: number, destinationId: number) => void;
  drawNavigationPath: (
    pathId: string,
    {
      shouldFocus,
      style,
      originIcon,
      destinationIcon,
    }: {
      shouldFocus?: boolean;
      style?: JIBESTREAM_STYLE;
      originIcon?: MAP_IMAGE;
      destinationIcon?: MAP_IMAGE;
    }
  ) => void;
  styleUnitsForDestination: (
    destinationId: number,
    style?: JIBESTREAM_STYLE
  ) => void;
  addMapIcon: (
    coordinates: number[],
    coordType: COORDINATE_TYPE,
    icon: MAP_IMAGE
  ) => void;
  //   styleShape: (id: number, style?: JIBESTREAM_STYLE) => void;
  //   styleGeofences: (visible: boolean, style?: JIBESTREAM_STYLE) => void;
};

export type MAP_SIMULATION_REFERENCE = {
  startPathSimulation: (
    path: GEOJSON_PATH,
    options: SIMULATION_OPTIONS,
  ) => void;
  controlSimulation: (
    command: SIMULATION_COMMAND,
  ) => SIMULATION_STATUS;
  getSimulationStatus: () => SIMULATION_STATUS;
  getSimulationsPaths: () => SIMULATION_PATH[];
}
