declare module "univer:sac/facade-migration-pack" {
  type UniverAPI = import("@univerjs/core/facade").FUniver;

  interface FacadeMigrationPack {
    readonly id: string;
    readonly description: string;
    readonly appliesAfter: string | null;
    readonly files: readonly string[];
    readonly [key: string]: unknown;
  }

  interface UnitMigrationContext {
    readonly univerAPI: UniverAPI;
  }

  interface UnitMigration {
    readonly apply: (context: UnitMigrationContext) => void | Promise<void>;
    readonly [key: string]: unknown;
  }

  interface FacadeMigrationModule {
    readonly pack: FacadeMigrationPack;
    readonly unitMigrations: readonly UnitMigration[];
  }

  function defineFacadeMigrationPack<T extends FacadeMigrationPack>(pack: T): T;
  function defineUnitMigration<T extends UnitMigration>(migration: T): T;
}

declare module "@univerjs/core/facade" {
  import type { FWorkbook } from "@univerjs/sheets/facade";

  interface FUniver {
    getWorkbook(localUnitId: string): FWorkbook;
    getWorkbookAsync(localUnitId: string): Promise<FWorkbook>;
  }
}

declare module "univer:sac/assertions" {
  type AssertionMatrix = readonly (readonly unknown[])[];
  type AssertionStyleTraits = Readonly<Record<string, unknown>>;
  type AssertionStyleMatrix = readonly (readonly AssertionStyleTraits[])[];
  type AssertionResourceObject = Readonly<Record<string, unknown>>;
  type AssertionResourceList = readonly AssertionResourceObject[];
  type AssertionColor = string | null;
  type AssertionColorMatrix = readonly (readonly AssertionColor[])[];

  interface AssertionSheetBuilder {
    exists(): void;
    filter(expected: AssertionResourceObject): void;
    tables(expected: AssertionResourceList): void;
    usedRange(expectedA1: string): void;
  }

  interface AssertionRangeBuilder {
    backgroundColors(expected: AssertionColorMatrix): void;
    cellData(expected: AssertionMatrix): void;
    conditionalFormats(expected: AssertionResourceList): void;
    displayValues(expected: AssertionMatrix): void;
    values(expected: AssertionMatrix): void;
    rawValues(expected: AssertionMatrix): void;
    numberFormats(expected: AssertionMatrix): void;
    formula(expected: string): void;
    formulas(expected: AssertionMatrix): void;
    styles(expected: AssertionStyleMatrix): void;
  }

  interface AssertionHelpers {
    sheet(name: string): AssertionSheetBuilder;
    range(targetA1: string): AssertionRangeBuilder;
  }

  interface AssertionSuite {
    readonly __sacAssertionSuite: true;
  }

  function defineAssertions(
    register: (helpers: AssertionHelpers) => void | Promise<void>
  ): AssertionSuite;
}
