export enum SystemState {
  IDLE = 'IDLE',
  RUNNING = 'RUNNING',
  ERROR = 'ERROR',
  PAUSED = 'PAUSED',
}

export interface AxisPosition {
  id: string;
  name: string;
  axis: 'X' | 'Y' | 'Z';
  value: number;
  speed: number;
  acc: number;
  dec: number;
}

export interface Recipe {
  id: string;
  name: string;
  lastModified: string;
  Motion?: string;
  BCD_1D?: boolean;
  BCD_QR?: boolean;
  BCD_DM?: boolean;
  DisableCamera?: boolean;
  DisablePrinter?: boolean;
  AutoOutConveyor?: number;
  [key: string]: any;
}

export interface IOPoint {
  id: number;
  name: string;
  type: 'input' | 'output';
  state: boolean;
}

export interface LogEntry {
  id: number;
  timestamp: string;
  message: string;
  type: 'info' | 'warning' | 'error';
}

export interface RobotTarget {
  x: number;
  y: number;
  z: number;
}

// WebView2 Native Bridge Types
export interface ConfigItem {
  Key: string;
  Value: string;
  Group: string;
  Type: 'String' | 'Number' | 'Boolean';
  Description: string;
}

export interface ProcessedDataRow {
  target: string;
  JTYPE: string;
  STIME: string;
  BATCH: string;
  SID: string;
  RID: string;
  VNAME: string;
  LOC: string;
  QTY: number;
  qtymax: number;
  MFGDATE: string;
  VLOT: string;
  PARTNO: string;
  MCN: string;
  REMARK: string;
  PRNATTACH: boolean;
  PRNVALID: boolean;
}

declare global {
  interface Window {
    chrome?: {
      webview?: {
        hostObjects: {
          machine: {
            MoveAxis(axis: string, value: number): Promise<void>;
            SetIO(id: number, isInput: boolean, state: boolean): Promise<void>;
            SystemControl(command: string): Promise<void>;
            SelectRecipe(recipeId: string): Promise<string>;
            CopyRecipe(recipeId: string, newName: string): Promise<string>;
            DeleteRecipe(recipeId: string): Promise<string>;
            GetConfig(): Promise<string>;
            GetIOList(): Promise<string>;
            GetRecipeList(): Promise<string>;
            GetRecipe(recipeTitle: string): Promise<string>;
            SaveRecipe(recipeTitle: string, recipeData: string): Promise<string>;
            SaveConfig(configJson: string): Promise<void>;
            InitializeDevice(): Promise<string>;
            GetInitializeStatus(): Promise<string>;
            GetProcessedData(): Promise<string>;
            // Vision control methods
            CameraConnect(): Promise<string>;
            CameraDisconnect(): Promise<string>;
            CameraGetImage(): Promise<string>;
            CameraLiveView(): Promise<string>;
            CameraReadTest(): Promise<string>;
            KeyenceTriggerOn(): Promise<string>;
            KeyenceTriggerOff(): Promise<string>;
            KeyenceGetImage(): Promise<string>;
            KeyenceSaveImage(): Promise<string>;
            // Light, Manual Print, Cancel Job
            ToggleLight(): Promise<string>;
            ExecuteManualPrint(sid: string, venderLot: string, qty: string, mfg: string, rid: string, spy: string, partNo: string, printer: string, count: number): Promise<string>;
            CancelJob(): Promise<string>;
            // Manage, Manual, Log Viewer
            OpenManage(): Promise<string>;
            CloseManage(): Promise<string>;
            OpenManual(): Promise<string>;
            OpenLogViewer(): Promise<string>;
            // Folder operations
            OpenProgramFolder(): Promise<string>;
            OpenLogFolder(): Promise<string>;
            OpenScreenshotFolder(): Promise<string>;
            OpenSavedDataFolder(): Promise<string>;
            // Picker Move methods
            GetPickerStatus(): Promise<string>;
            PickerMoveLeft(): Promise<string>;
            PickerMoveLeftWait(): Promise<string>;
            PickerMoveCenter(): Promise<string>;
            PickerMoveRightWait(): Promise<string>;
            PickerMoveRight(): Promise<string>;
            PickerJogStart(direction: string): Promise<string>;
            PickerJogStop(): Promise<string>;
            PickerStop(): Promise<string>;
            CancelVisionValidation(side: string): Promise<string>;
            PickerManagePosition(side: string): Promise<string>;
            PickerManageReturn(): Promise<string>;
            PickerZHome(): Promise<string>;
            PickerZZero(): Promise<string>;
            PickerTestPrint(side: string): Promise<string>;
            CanCloseManage(): Promise<string>;
            // Interlock methods
            ToggleInterlock(axisIndex: number, lockIndex: number): Promise<string>;
            GetInterlockList(): Promise<string>;
            // HW Status methods
            GetHWStatus(): Promise<string>;
            // History dialog
            OpenHistory(): Promise<string>;
            // History data
            GetHistoryData(startDate: string, endDate: string, search: string): Promise<string>;
          }
        };
        addEventListener(type: string, listener: (event: any) => void): void;
        removeEventListener(type: string, listener: (event: any) => void): void;
        postMessage(message: any): void;
      }
    }
  }
}