import * as GaussianSplats3D from '@mkkellogg/gaussian-splats-3d';

export type GaussianVector3 = [number, number, number];
export type GaussianQuaternion = [number, number, number, number];
export type GaussianOrientationPreset = 'identity' | 'x-90' | 'x90' | 'x180' | 'y-90' | 'y90' | 'z-90' | 'z90' | 'z180';

export interface EngineGaussianOptions {
  containerId: string;
  cameraUp?: GaussianVector3;
  initialCameraPosition?: GaussianVector3;
  initialCameraLookAt?: GaussianVector3;
  backgroundColor?: string;
  antialias?: boolean;
  showLoadingUI?: boolean;
  sharedMemoryForWorkers?: boolean;
  gpuAcceleratedSort?: boolean;
  sphericalHarmonicsDegree?: number;
  orientationPreset?: GaussianOrientationPreset;
  viewerOptions?: Record<string, any>;
}

export interface GaussianSceneOptions {
  id?: string;
  name?: string;
  format?: number;
  splatAlphaRemovalThreshold?: number;
  showLoadingUI?: boolean;
  position?: GaussianVector3;
  rotation?: GaussianQuaternion;
  scale?: GaussianVector3;
  progressiveLoad?: boolean;
  onProgress?: (...args: any[]) => void;
  [key: string]: any;
}

export interface GaussianSceneInfo {
  id: string;
  name: string;
  url: string;
  index: number;
  options: GaussianSceneOptions;
}

export interface GaussianFpsInfo {
  fps: number;
  frameTimeMs: number;
  minFps: number;
}

export enum EventTypeGaussian {
  LoadStart = 'gaussian-load-start',
  LoadProgress = 'gaussian-load-progress',
  Loaded = 'gaussian-loaded',
  LoadError = 'gaussian-load-error',
  SceneRemoved = 'gaussian-scene-removed',
  FpsUpdated = 'gaussian-fps-updated',
  ViewChanged = 'gaussian-view-changed'
}

export declare class EngineKernelGaussian {
  constructor(options: EngineGaussianOptions);
  loadModel(url: string, options?: GaussianSceneOptions): Promise<GaussianSceneInfo>;
  unloadModel(id: string): Promise<void>;
  setOrientationPreset(preset: GaussianOrientationPreset): void;
  getOrientationPreset(): GaussianOrientationPreset;
  resize(width?: number, height?: number): void;
  pauseRendering(): void;
  resumeRendering(): void;
  resetFpsStats(): void;
  getFpsInfo(): GaussianFpsInfo;
  on<T = any>(event: EventTypeGaussian, callback: (data: T) => void): void;
  off<T = any>(event: EventTypeGaussian, callback: (data: T) => void): void;
  getVersion(): string;
  dispose(): Promise<void>;
}

export declare function createEngineGaussian(options: EngineGaussianOptions): EngineKernelGaussian;
export { createEngineGaussian as createGaussian };
export { GaussianSplats3D };
export default createEngineGaussian;
