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

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

  interface IFSheetsSortEventNameMixin {
      /**
       * This event will be emitted when a range on a worksheet is sorted.
       * @see {@link ISheetRangeSortParams}
       * @example
       * ```typescript
       * const callbackDisposable = univerAPI.addEvent(univerAPI.Event.SheetRangeSorted, (params) => {
       *   console.log(params);
       *   const { workbook, worksheet, range, sortColumn } = params;
       * });
       *
       * // Remove the event listener, use `callbackDisposable.dispose()`
       * ```
       */
      SheetRangeSorted: 'SheetRangeSorted';
      /**
       * This event will be emitted before sorting a range on a worksheet.
       * @see {@link ISheetRangeSortParams}
       * @example
       * ```typescript
       * const callbackDisposable = univerAPI.addEvent(univerAPI.Event.SheetBeforeRangeSort, (params) => {
       *   console.log(params);
       *   const { workbook, worksheet, range, sortColumn } = params;
       *
       *   // Cancel the sorting operation.
       *   params.cancel = true;
       * });
       *
       * // Remove the event listener, use `callbackDisposable.dispose()`
       * ```
       */
      SheetBeforeRangeSort: 'SheetBeforeRangeSort';
  }

  class FSheetsSortEventNameMixin {
      get SheetRangeSorted(): 'SheetRangeSorted';
      get SheetBeforeRangeSort(): 'SheetBeforeRangeSort';
  }

  interface ISortColumn {
      column: number;
      ascending: boolean;
  }

  interface ISheetsRangeSortEventParams extends IEventBase {
      workbook: FWorkbook;
      worksheet: FWorksheet;
      range: FRange;
      sortColumn: ISortColumn[];
  }

  interface ISheetsSortEventParamConfig {
      SheetBeforeRangeSort: ISheetsRangeSortEventParams;
      SheetRangeSorted: ISheetsRangeSortEventParams;
  }

  type SortColumnSpec = {
      column: number;
      ascending: boolean;
  } | number;

  interface IFRangeSheetsSortMixin {
      /**
       * Sorts the cells in the given range, by column(s) and order specified.
       * @param {SortColumnSpec | SortColumnSpec[]} column The column index with order or an array of column indexes with order. The range first column index is 0.
       * @returns {FRange} The range itself for chaining.
       * @example
       * ```typescript
       * const fWorkbook = univerAPI.getActiveWorkbook();
       * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
       * if (!fWorksheet) return;
       * const fRange = fWorksheet.getRange('D1:G10');
       *
       * // Sorts the range by the first column in ascending order.
       * fRange.sort(0);
       *
       * // Sorts the range by the first column in descending order.
       * fRange.sort({ column: 0, ascending: false });
       *
       * // Sorts the range by the first column in descending order and the second column in ascending order.
       * fRange.sort([{ column: 0, ascending: false }, 1]);
       * ```
       */
      sort(column: SortColumnSpec | SortColumnSpec[]): FRange;
  }

  class FRangeSheetsSortMixin {
      sort(column: SortColumnSpec | SortColumnSpec[]): FRange;
  }

  class FUniverSheetsSortMixin {
  }

  interface IFWorksheetSortMixin {
      /**
       * Sort the worksheet by the specified column.
       * @param {number} colIndex The column index to sort by.
       * @param {boolean} [asc=true] The sort order. `true` for ascending, `false` for descending. The column A index is 0.
       * @returns {FWorksheet} The worksheet itself for chaining.
       * @example
       * ```typescript
       * const fWorkbook = univerAPI.getActiveWorkbook();
       * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
       * if (!fWorksheet) return;
       *
       * // Sorts the worksheet by the column A in ascending order.
       * fWorksheet.sort(0);
       *
       * // Sorts the worksheet by the column A in descending order.
       * fWorksheet.sort(0, false);
       * ```
       */
      sort(colIndex: number, asc?: boolean): FWorksheet;
  }

  class FWorksheetSortMixin {
      sort(colIndex: number, asc?: boolean): FWorksheet;
  }
}

declare module "@univerjs/core/facade" {
  import type { IFSheetsSortEventNameMixin, ISheetsSortEventParamConfig } from "@univerjs/sheets-sort/facade";

  interface FEventName extends IFSheetsSortEventNameMixin {
  }

  interface IEventParamConfig extends ISheetsSortEventParamConfig {
  }
}

declare module "@univerjs/sheets/facade" {
  import type { IFRangeSheetsSortMixin, IFWorksheetSortMixin } from "@univerjs/sheets-sort/facade";

  interface FRange extends IFRangeSheetsSortMixin {
  }
}

declare module "@univerjs/sheets/facade" {
  import type { IFRangeSheetsSortMixin, IFWorksheetSortMixin } from "@univerjs/sheets-sort/facade";

  interface FWorksheet extends IFWorksheetSortMixin {
  }
}
