import { ApiBase } from './ApiBase';
import { Fdc3InternalApi } from '../Internal/Fdc3InternalApi';
import { ContextConfiguration } from '../../AdaptableState/Common/Fdc3Context';
export class Fdc3ApiImpl extends ApiBase {
    internalApi;
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new Fdc3InternalApi(_adaptable);
    }
    getDesktopAgent() {
        return this.getFdc3Service().getDesktopAgent();
    }
    buildContextDataFromRow(contextType, rowNode) {
        return this.internalApi.mapRowToContextData(contextType, rowNode);
    }
    buildContextDataForPrimaryKey(contextType, primaryKeyValue) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKeyValue);
        if (!rowNode) {
            this.logWarn(`No row found for primary key value '${primaryKeyValue}'`);
            return undefined;
        }
        return this.buildContextDataFromRow(contextType, rowNode);
    }
    raiseIntentFromPrimaryKey(primaryKeyValue, intent, contextType, appIdentifier) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKeyValue);
        if (!rowNode) {
            this.logWarn(`No row found for primary key value '${primaryKeyValue}'`);
            return undefined;
        }
        return this.raiseIntentFromRow(rowNode, intent, contextType, appIdentifier);
    }
    raiseIntentFromRow(rowNode, intent, contextType, appIdentifier) {
        const contextData = this.buildContextDataFromRow(contextType, rowNode);
        return this.getFdc3Service().raiseIntent(intent, contextData, appIdentifier);
    }
    raiseIntentForContextFromRow(rowNode, contextType, appIdentifier) {
        const contextData = this.buildContextDataFromRow(contextType, rowNode);
        return this.getFdc3Service().raiseIntentForContext(contextData, appIdentifier);
    }
    raiseIntentForContextFromPrimaryKey(primaryKeyValue, contextType, appIdentifier) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKeyValue);
        if (!rowNode) {
            this.logWarn(`No row found for primary key value '${primaryKeyValue}'`);
            return undefined;
        }
        return this.raiseIntentForContextFromRow(rowNode, contextType, appIdentifier);
    }
    broadcastFromRow(rowNode, contextType, channel) {
        const contextData = this.buildContextDataFromRow(contextType, rowNode);
        return this.getFdc3Service().broadcast(contextData, channel);
    }
    broadcastFromPrimaryKey(primaryKeyValue, contextType, channel) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKeyValue);
        if (!rowNode) {
            this.logWarn(`No row found for primary key value '${primaryKeyValue}'`);
            return undefined;
        }
        return this.broadcastFromRow(rowNode, contextType, channel);
    }
    getContextLabel(contextType) {
        return this.isStandardContextType(contextType)
            ? ContextConfiguration[contextType]?.label
            : contextType;
    }
    isStandardContextType(contextType) {
        return this.internalApi.isStandardContextType(contextType);
    }
    isStandardIntentType(intentType) {
        return this.internalApi.isStandardIntentType(intentType);
    }
    getFdc3Service() {
        return this.getAdaptableInternalApi().getFdc3Service();
    }
}
