import type {
  ConfigDiskSensorBallShooterModuleOptions,
  ConfigureBallSensorDiskThrowerModuleOptions,
  FlagConfigurationOptions,
  FlagShowMediaOptions,
  PlaySoundOptions,
  RGBConfigurationOptions,
  RGBShowEffectOptions,
  ScreenCountdownParams,
  ScreenFinishViewInput,
  ScreenUpdateGameViewInput,
  SpeedChangeOptions,
  SpeedConfiguration,
  StarLaserConfigureModuleOptions,
  StarLaserSendActionsOptions,
} from '../hardware';
import type { ArithmeticExpression } from '../utils';

export interface ChangeSpeedActionCommandOptions extends Omit<SpeedChangeOptions, 'speed'> {
  speed: number | ArithmeticExpression;
}

export interface PlaySoundActionCommandOptions extends Omit<PlaySoundOptions, 'durationMs'> {
  durationMs?: number | ArithmeticExpression;
}

export type BallSensorDiskThrowerModuleCommands =
  | { module: 'ballSensorDiskThrower'; action: 'activateSensor'; params?: undefined }
  | { module: 'ballSensorDiskThrower'; action: 'deactivateSensor'; params?: undefined }
  | {
      module: 'ballSensorDiskThrower';
      action: 'configureModule';
      params: ConfigureBallSensorDiskThrowerModuleOptions;
    }
  | { module: 'ballSensorDiskThrower'; action: 'throwDisk'; params?: undefined }
  | { module: 'ballSensorDiskThrower'; action: 'activateDiskThrower'; params?: undefined }
  | { module: 'ballSensorDiskThrower'; action: 'deactivateDiskThrower'; params?: undefined };

export type DiskSensorBallShooterModuleCommands =
  | { module: 'diskSensorBallShooter'; action: 'configure'; params: ConfigDiskSensorBallShooterModuleOptions }
  | { module: 'diskSensorBallShooter'; action: 'prepareShooter'; params?: undefined }
  | { module: 'diskSensorBallShooter'; action: 'shootBall'; params?: undefined }
  | { module: 'diskSensorBallShooter'; action: 'activateSensor'; params?: undefined }
  | { module: 'diskSensorBallShooter'; action: 'deactivateSensor'; params?: undefined }
  | { module: 'diskSensorBallShooter'; action: 'calibrateSensor'; params?: undefined };

export type FlagModuleCommands =
  | { module: 'flag'; action: 'activate'; params?: undefined }
  | { module: 'flag'; action: 'deactivate'; params?: undefined }
  | { module: 'flag'; action: 'configure'; params: FlagConfigurationOptions }
  | { module: 'flag'; action: 'showMediaIndefinitely'; params: FlagShowMediaOptions }
  | { module: 'flag'; action: 'showMediaTemporarily'; params: FlagShowMediaOptions };

export type RGBModuleCommands =
  | { module: 'rgb'; action: 'configure'; params: RGBConfigurationOptions }
  | { module: 'rgb'; action: 'showEffect'; params: RGBShowEffectOptions };

export type SpeedModuleCommands =
  | { module: 'speed'; action: 'activate'; params?: undefined }
  | { module: 'speed'; action: 'deactivate'; params?: undefined }
  | { module: 'speed'; action: 'change'; params: ChangeSpeedActionCommandOptions }
  | { module: 'speed'; action: 'configure'; params: SpeedConfiguration };

export type LeftStarBackLaserModuleCommands =
  | { module: 'leftStarBackLaser'; action: 'action'; params: StarLaserSendActionsOptions }
  | { module: 'leftStarBackLaser'; action: 'configure'; params: StarLaserConfigureModuleOptions };

export type RightStarFrontLaserModuleCommands =
  | { module: 'rightStarFrontLaser'; action: 'action'; params: StarLaserSendActionsOptions }
  | { module: 'rightStarFrontLaser'; action: 'configure'; params: StarLaserConfigureModuleOptions };

export type ScreenModuleCommands =
  | { module: 'screen'; action: 'showHomeView'; params?: undefined }
  | { module: 'screen'; action: 'showCountdownView'; params: ScreenCountdownParams }
  | { module: 'screen'; action: 'updateGameView'; params: ScreenUpdateGameViewInput }
  | { module: 'screen'; action: 'showScreenVictoryView'; params: ScreenFinishViewInput }
  | { module: 'screen'; action: 'showScreenDefeatView'; params: ScreenFinishViewInput };

export type SteeringWheelModuleCommands =
  | { module: 'steeringWheel'; action: 'turnLedOn'; params?: undefined }
  | { module: 'steeringWheel'; action: 'turnLedOff'; params?: undefined };

export type SoundModuleCommands = { module: 'sound'; action: 'play'; params: PlaySoundActionCommandOptions };

export type AllCommandsConfig =
  | BallSensorDiskThrowerModuleCommands
  | DiskSensorBallShooterModuleCommands
  | FlagModuleCommands
  | RGBModuleCommands
  | SpeedModuleCommands
  | LeftStarBackLaserModuleCommands
  | RightStarFrontLaserModuleCommands
  | ScreenModuleCommands
  | SteeringWheelModuleCommands
  | SoundModuleCommands;
