/**
 * Copyright 2023-present DreamNum Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import type { ICollaborator, IListPermPointResponse } from '@univerjs/protocol';
import type { IDisposable } from '../../common/di';
import type { ObjectPermissionRuleModel } from './object-permission-rule.model';
import type { IPermissionPoint } from './type';
import { UnitObject } from '@univerjs/protocol';
import { Injector } from '../../common/di';
import { Disposable } from '../../shared/lifecycle';
import { ICommandService } from '../command/command.service';
import { IConfigService } from '../config/config.service';
import { ILogService } from '../log/log.service';
import { UserManagerService } from '../user-manager/user-manager.service';
import { IPermissionService } from './type';
export interface IObjectPermissionTarget {
    unitId: string;
    objectId: string;
    objectType: IPermissionPoint['type'];
}
export interface IObjectPermissionPolicy {
    /** All Unit editors, the object owner, or selected Unit collaborators. Parent restrictions still apply. */
    edit: 'all' | 'owner' | 'members';
    collaborators: ICollaborator[];
    strategies: IListPermPointResponse['objects'][number]['strategies'];
}
export interface IObjectPermissionChange {
    objectId: string;
    /** null removes protection and restores inheritance; it never deletes the object. */
    policy: IObjectPermissionPolicy | null;
}
export interface ISetObjectPermissionsCommandParams {
    unitId: string;
    changes: IObjectPermissionChange[];
}
export interface IObjectPermissionBatchResult {
    succeeded: string[];
    failed: {
        objectId: string;
        error: unknown;
    }[];
    /** Writes have already completed; a refresh failure must not cause successful objects to be retried. */
    refreshError?: unknown;
}
/** Frontend opt-in; does not change the Authz service interface or existing local setters. */
export declare const OBJECT_PERMISSION_CONFIG_KEY = "objectPermissionTypes";
/** Coordinates Authz policy writes and the current user's effective permission cache. */
export declare class ObjectPermissionService extends Disposable {
    private readonly _injector;
    private readonly _permissions;
    private readonly _logService;
    private readonly _users;
    private readonly _config;
    private readonly _commands;
    private readonly _models;
    private readonly _initialized;
    private readonly _policies;
    private readonly _generations;
    private _nextGeneration;
    private readonly _revision;
    readonly changed$: import("rxjs").Observable<number>;
    private readonly _unitChanges;
    readonly unitChanges$: import("rxjs").Observable<string>;
    constructor(_injector: Injector, _permissions: IPermissionService, _logService: ILogService, _users: UserManagerService, _config: IConfigService, _commands: ICommandService);
    private get _authz();
    registerRuleModel(rootType: UnitObject, model: ObjectPermissionRuleModel, mutationId: string, batchMutationId?: string): IDisposable;
    private _getRule;
    private _getAuthzId;
    initializeUnit(target: IObjectPermissionTarget): void;
    supports(target: IObjectPermissionTarget): boolean;
    getPolicies(unitId: string): readonly IListPermPointResponse['objects'][number][];
    hasPolicy(target: IObjectPermissionTarget): boolean;
    /** Match Sheet's permission-list entry: require effective file editing, not child editing. */
    canView(target: IObjectPermissionTarget): boolean;
    canManage(target: IObjectPermissionTarget): Promise<boolean>;
    canDelete(target: IObjectPermissionTarget): Promise<boolean>;
    /** Must be called from a product permission Command; removal restores inheritance by detaching the rule. */
    remove(target: IObjectPermissionTarget): Promise<void>;
    private _commitRule;
    private _getPolicy;
    private _allowed;
    private _canChangeRule;
    read(target: IObjectPermissionTarget): Promise<IObjectPermissionPolicy>;
    setPoint(target: IObjectPermissionTarget, point: IPermissionPoint, value: boolean): Promise<void>;
    /** Must be called from a product permission Command. */
    save(target: IObjectPermissionTarget, policy: IObjectPermissionPolicy): Promise<void>;
    private _writePolicy;
    /**
     * Called by product Commands. Authz writes remain per object, so failures are reported per object.
     * Successful binding changes share one undo entry; updates to existing remote policies are not undoable.
     */
    saveMany(changes: (IObjectPermissionTarget & {
        policy: IObjectPermissionPolicy | null;
    })[]): Promise<IObjectPermissionBatchResult>;
    refreshUnit(unitId: string): Promise<void>;
    clearUnit(unitId: string): void;
    private _assertSupported;
}
