declare module "@univerjs/core/facade" {
  import type { ISheetsNoteEventParamConfig } from "@univerjs/sheets-note/facade";

  interface IFSheetsNoteEventNameMixin {
      /**
       * Event fired when a note is added
       * @see {@link ISheetNoteAddEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteAdd, (params) => {
       *   const { workbook, worksheet, row, col, note } = params;
       *   console.log(params);
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly SheetNoteAdd: 'SheetNoteAdd';
      /**
       * Event fired when a note is deleted
       * @see {@link ISheetNoteDeleteEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteDelete, (params) => {
       *   const { workbook, worksheet, row, col, oldNote } = params;
       *   console.log(params);
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly SheetNoteDelete: 'SheetNoteDelete';
      /**
       * Event fired when a note is updated
       * @see {@link ISheetNoteUpdateEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteUpdate, (params) => {
       *   const { workbook, worksheet, row, col, note, oldNote } = params;
       *   console.log(params);
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly SheetNoteUpdate: 'SheetNoteUpdate';
      /**
       * Event fired when a note is shown
       * @see {@link ISheetNoteShowEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteShow, (params) => {
       *   const { workbook, worksheet, row, col } = params;
       *   console.log(params);
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly SheetNoteShow: 'SheetNoteShow';
      /**
       * Event fired when a note is hidden
       * @see {@link ISheetNoteHideEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteHide, (params) => {
       *   const { workbook, worksheet, row, col } = params;
       *   console.log(params);
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly SheetNoteHide: 'SheetNoteHide';
      /**
       * Event fired before a note is added
       * @see {@link ISheetNoteAddEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteAdd, (params) => {
       *   const { workbook, worksheet, row, col, note } = params;
       *   console.log(params);
       *
       *   // Cancel the note addition operation
       *   params.cancel = true;
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly BeforeSheetNoteAdd: 'BeforeSheetNoteAdd';
      /**
       * Event fired before a note is deleted
       * @see {@link ISheetNoteDeleteEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteDelete, (params) => {
       *   const { workbook, worksheet, row, col, oldNote } = params;
       *   console.log(params);
       *
       *   // Cancel the note deletion operation
       *   params.cancel = true;
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly BeforeSheetNoteDelete: 'BeforeSheetNoteDelete';
      /**
       * Event fired before a note is updated
       * @see {@link ISheetNoteUpdateEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteUpdate, (params) => {
       *   const { workbook, worksheet, row, col, note, oldNote } = params;
       *   console.log(params);
       *
       *   // Cancel the note update operation
       *   params.cancel = true;
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly BeforeSheetNoteUpdate: 'BeforeSheetNoteUpdate';
      /**
       * Event fired before a note is shown
       * @see {@link ISheetNoteShowEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteShow, (params) => {
       *   const { workbook, worksheet, row, col } = params;
       *   console.log(params);
       *
       *   // Cancel the note show operation
       *   params.cancel = true;
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly BeforeSheetNoteShow: 'BeforeSheetNoteShow';
      /**
       * Event fired before a note is hidden
       * @see {@link ISheetNoteHideEventParams}
       * @example
       * ```ts
       * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteHide, (params) => {
       *   const { workbook, worksheet, row, col } = params;
       *   console.log(params);
       *
       *   // Cancel the note hide operation
       *   params.cancel = true;
       * });
       *
       * // Remove the event listener, use `disposable.dispose()`
       * ```
       */
      readonly BeforeSheetNoteHide: 'BeforeSheetNoteHide';
  }
}

declare module "@univerjs/sheets-note" {
  interface ISheetNote {
      id: string;
      row: number;
      col: number;
      width: number;
      height: number;
      note: string;
      show?: boolean;
  }
}

declare module "@univerjs/sheets-note/facade" {
  import type { Nullable } from "@univerjs/core";

  import type { ISheetNote } from "@univerjs/sheets-note";

  import type { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";

  interface ISheetNoteAddEventParams {
      workbook: FWorkbook;
      worksheet: FWorksheet;
      row: number;
      col: number;
      note: ISheetNote;
      cancel?: boolean;
  }

  interface ISheetNoteDeleteEventParams {
      workbook: FWorkbook;
      worksheet: FWorksheet;
      row: number;
      col: number;
      oldNote: ISheetNote;
      cancel?: boolean;
  }

  interface ISheetNoteUpdateEventParams {
      workbook: FWorkbook;
      worksheet: FWorksheet;
      row: number;
      col: number;
      note: ISheetNote;
      oldNote: ISheetNote;
      cancel?: boolean;
  }

  interface ISheetNoteShowEventParams {
      workbook: FWorkbook;
      worksheet: FWorksheet;
      row: number;
      col: number;
      cancel?: boolean;
  }

  interface ISheetNoteHideEventParams {
      workbook: FWorkbook;
      worksheet: FWorksheet;
      row: number;
      col: number;
      cancel?: boolean;
  }

  interface ISheetsNoteEventParamConfig {
      SheetNoteAdd: ISheetNoteAddEventParams;
      SheetNoteDelete: ISheetNoteDeleteEventParams;
      SheetNoteUpdate: ISheetNoteUpdateEventParams;
      SheetNoteShow: ISheetNoteShowEventParams;
      SheetNoteHide: ISheetNoteHideEventParams;
      BeforeSheetNoteAdd: ISheetNoteAddEventParams;
      BeforeSheetNoteDelete: ISheetNoteDeleteEventParams;
      BeforeSheetNoteUpdate: ISheetNoteUpdateEventParams;
      BeforeSheetNoteShow: ISheetNoteShowEventParams;
      BeforeSheetNoteHide: ISheetNoteHideEventParams;
  }

  class FSheetsNoteEventNameMixin {
      get SheetNoteAdd(): 'SheetNoteAdd';
      get SheetNoteDelete(): 'SheetNoteDelete';
      get SheetNoteUpdate(): 'SheetNoteUpdate';
      get SheetNoteShow(): 'SheetNoteShow';
      get SheetNoteHide(): 'SheetNoteHide';
      get BeforeSheetNoteAdd(): 'BeforeSheetNoteAdd';
      get BeforeSheetNoteDelete(): 'BeforeSheetNoteDelete';
      get BeforeSheetNoteUpdate(): 'BeforeSheetNoteUpdate';
      get BeforeSheetNoteShow(): 'BeforeSheetNoteShow';
      get BeforeSheetNoteHide(): 'BeforeSheetNoteHide';
  }

  interface ISheetsNoteEventParamConfig {
      SheetNoteAdd: ISheetNoteAddEventParams;
      SheetNoteDelete: ISheetNoteDeleteEventParams;
      SheetNoteUpdate: ISheetNoteUpdateEventParams;
      SheetNoteShow: ISheetNoteShowEventParams;
      SheetNoteHide: ISheetNoteHideEventParams;
      BeforeSheetNoteAdd: ISheetNoteAddEventParams;
      BeforeSheetNoteDelete: ISheetNoteDeleteEventParams;
      BeforeSheetNoteUpdate: ISheetNoteUpdateEventParams;
      BeforeSheetNoteShow: ISheetNoteShowEventParams;
      BeforeSheetNoteHide: ISheetNoteHideEventParams;
  }

  interface ICreateOrUpdateNoteOptions {
      id?: string;
      width: number;
      height: number;
      note: string;
      show?: boolean;
  }

  interface IFRangeSheetsNoteMixin {
      /**
       * Get the annotation of the top-left cell in the range
       * @returns {Nullable<ISheetNote>} The annotation of the top-left cell in the range
       * @example
       * ```ts
       * const fWorkbook = univerAPI.getActiveWorkbook();
       * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
       * if (!fWorksheet) return;
       * const fRange = fWorksheet.getRange('A1:D10');
       * const note = fRange.getNote();
       * console.log(note);
       * ```
       */
      getNote(): Nullable<ISheetNote>;
      /**
       * Create or update the annotation of the top-left cell in the range
       * @param {ICreateOrUpdateNoteOptions} note The annotation to create or update
       * @returns {FRange} This range for method chaining
       * @example
       * ```ts
       * const fWorkbook = univerAPI.getActiveWorkbook();
       * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
       * if (!fWorksheet) return;
       * const fRange = fWorksheet.getRange('A1');
       * fRange.createOrUpdateNote({
       *   note: 'This is a note',
       *   width: 160,
       *   height: 100,
       *   show: true,
       * });
       * ```
       */
      createOrUpdateNote(note: ICreateOrUpdateNoteOptions): FRange;
      /**
       * Delete the annotation of the top-left cell in the range
       * @returns {FRange} This range for method chaining
       * @example
       * ```ts
       * const fWorkbook = univerAPI.getActiveWorkbook();
       * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
       * if (!fWorksheet) return;
       * const notes = fWorksheet.getNotes();
       * console.log(notes);
       *
       * if (notes.length > 0) {
       *   // Delete the first note
       *   const { row, col } = notes[0];
       *   fWorksheet.getRange(row, col).deleteNote();
       * }
       * ```
       */
      deleteNote(): FRange;
  }

  class FRangeSheetsNoteMixin {
      createOrUpdateNote(note: ICreateOrUpdateNoteOptions): FRange;
      deleteNote(): FRange;
      getNote(): Nullable<ISheetNote>;
  }

  class FUniverSheetsNoteMixin {
  }

  interface IFWorksheetNoteMixin {
      /**
       * Get all annotations in the worksheet
       * @returns {ISheetNote[]} An array of all annotations in the worksheet
       * @example
       * ```ts
       * const fWorkbook = univerAPI.getActiveWorkbook();
       * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
       * if (!fWorksheet) return;
       * const notes = fWorksheet.getNotes();
       * console.log(notes);
       *
       * notes.forEach((item) => {
       *   const { row, col, note } = item;
       *   console.log(`Cell ${fWorksheet.getRange(row, col).getA1Notation()} has a note: ${note}`);
       * });
       * ```
       */
      getNotes(): ISheetNote[];
  }

  class FWorksheetNoteMixin {
      getNotes(): ISheetNote[];
  }
}

declare module "@univerjs/core/facade" {
  import type { ISheetsNoteEventParamConfig } from "@univerjs/sheets-note/facade";

  interface FEventName extends IFSheetsNoteEventNameMixin {
  }

  interface IEventParamConfig extends ISheetsNoteEventParamConfig {
  }
}

declare module "@univerjs/sheets/facade" {
  import type { IFRangeSheetsNoteMixin, IFWorksheetNoteMixin } from "@univerjs/sheets-note/facade";

  interface FRange extends IFRangeSheetsNoteMixin {
  }
}

declare module "@univerjs/sheets/facade" {
  import type { IFRangeSheetsNoteMixin, IFWorksheetNoteMixin } from "@univerjs/sheets-note/facade";

  interface FWorksheet extends IFWorksheetNoteMixin {
  }
}

declare module "@univerjs/sheets-note/facade" {
  import type { ISheetNote } from "@univerjs/sheets-note";
  import type { FRange } from "@univerjs/sheets/facade";

  interface ICreateOrUpdateNoteOptions {
    id?: string;
    width: number;
    height: number;
    note: string;
    show?: boolean;
  }

  interface IFRangeSheetsNoteMixin {
    createOrUpdateNote(note: ICreateOrUpdateNoteOptions): FRange;
  }
}
