import type { DocumentField, FieldApplyResult, FieldChange } from '../domain/types';

export interface OnlyOfficeScope {
  [key: string]: unknown;
  elnTemplateFillChanges?: FieldChange[];
  elnTemplateFillInspect?: Record<string, never>;
}

export interface AscPlugin {
  button?: (id: number) => void;
  callCommand: (command: () => string, isClose: boolean, isCalc: boolean, callback: (result: unknown) => void) => boolean | void;
  executeCommand: (command: string, data: string) => unknown;
  executeMethod: (name: string, args: unknown[], callback: (result: unknown) => void) => boolean | void;
  info?: { options?: unknown };
  init?: () => void;
  onThemeChanged?: (theme: unknown) => void;
  onThemeChangedBase: (theme: unknown) => void;
}

export interface AscGlobal { plugin: AscPlugin; scope: OnlyOfficeScope }

export interface InspectResult { fields: DocumentField[]; ok: boolean; error?: string }
export interface ApplyResult { results: FieldApplyResult[]; ok: boolean; error?: string }

declare global {
  const Api: any;
  const Asc: { scope: OnlyOfficeScope };
  interface Window { Asc?: AscGlobal }
}
