declare namespace BDV {
  interface Api {
    readonly apiClient: any;
    readonly apiUrl?: string;
    readonly archiveUrl?: string;
    readonly cloudId: number;
    readonly projectId: number;
    readonly permissions: Permissions;
    accessToken: string;

    getModel(modelId: number): Promise<ApiModel>;
    getModelStructure(model: ApiModel): Promise<any>;
    getRawElements(modelId: number): Promise<any>;
    getStoreys(modelId: number): Promise<ApiStorey[]>;
    createModel(docId: number): Promise<ApiModel>;
    waitForModelProcess(model: ApiModel): Promise<ApiModel>;
    createStoreyPlan(modelId: number, storeyUuid: string, docId: number): Promise<ApiPlan>;
    deleteStoreyPlan(modelId: number, storeyUuid: string, planId: number): Promise<void>;
    updatePlanPositioning(modelId: number, storeyUuid: string, planId: number, positioning: ApiPositionning): Promise<ApiPositionning>;
  }

  interface ApiDocument {
    id: number;
    parent_id?: number;
    name: string;
    file_name: string;
    file: string;
    model_id?: number;
    model_type?: ModelType;
  }

  interface ApiModel {
    id: number;
    name: string;
    type: ModelType;
    source: ModelSource;
    status: ModelStatus;
    archived: boolean;
    project_id: number;
    document_id: number;
    document?: ApiDocument;

    // Model files
    preview_file?: string;
    structure_file?: string;
    /** @deprecated use `xkt_files` instead */
    xkt_file?: string;
    xkt_files?: { version: number; file: string }[];
    gltf_file?: string;
    map_file?: string;
    binary_2d_file?: string;

    // Misc
    world_position?: number[];
    north_vector?: number[][];
    recommanded_2d_angle?: number;
    size_ratio?: number;

    // Multi-page PDF / Multi layout DWG
    page_number?: number;
    layout_name?: string;
    parent_id?: number;
    children?: ApiModel[];
  }

  type ApiPlan = ApiModel;

  interface ApiObject {
    uuid: string;
    name: string;
    longname: string;
    type: string;
    object_type: string;
    children: ApiObject[];
  }

  interface ApiStorey {
    uuid: string;
    name: string;
    plans: (ApiPositionning & { plan: ApiPlan })[];
  }

  interface ApiPositionning {
    translation_x: number;
    translation_y: number;
    rotate_z: number;
    scale: number;
    opacity: number;
  }

  interface Permissions {
    hasReadPermission: boolean;
    hasWritePermission: boolean;
    hasAdminPermission: boolean;
    hasBcfReadPermission: boolean;
    hasBcfWritePermission: boolean;
    hasDocReadPermission: boolean;
    hasDocWritePermission: boolean;
    hasModelReadPermission: boolean;
    hasModelWritePermission: boolean;
    tokenScopes: {
      bcf?: string[];
      document?: string[];
      model?: string[];
    };
    usableScopes: {
      bcf?: string[];
      document?: string[];
      model?: string[];
    };
    userRole?: string;
    user?: {
      id: number;
      email: string;
      firstName: string;
      lastName: string;
      created_at: string;
      updated_at: string;
      provider: string;
      sub: string;
      profile_picture: string;
    };
  }
}
