import { MainContext } from './extHost.protocol.js';
import { Disposable } from './extHostTypes.js';
class ExtHostIssueReporter {
    constructor(mainContext) {
        this._IssueUriRequestHandlers = ( new Map());
        this._IssueDataProviders = ( new Map());
        this._proxy = ( mainContext.getProxy(MainContext.MainThreadIssueReporter));
    }
    async $getIssueReporterUri(extensionId, token) {
        if (this._IssueUriRequestHandlers.size === 0) {
            throw ( new Error('No issue request handlers registered'));
        }
        const provider = this._IssueUriRequestHandlers.get(extensionId);
        if (!provider) {
            throw ( new Error('Issue request handler not found'));
        }
        const result = await provider.handleIssueUrlRequest();
        if (!result) {
            throw ( new Error('Issue request handler returned no result'));
        }
        return result;
    }
    async $getIssueReporterData(extensionId, token) {
        if (this._IssueDataProviders.size === 0) {
            throw ( new Error('No issue request handlers registered'));
        }
        const provider = this._IssueDataProviders.get(extensionId);
        if (!provider) {
            throw ( new Error('Issue data provider not found'));
        }
        const result = await provider.provideIssueData(token);
        if (!result) {
            throw ( new Error('Issue data provider returned no result'));
        }
        return result;
    }
    async $getIssueReporterTemplate(extensionId, token) {
        if (this._IssueDataProviders.size === 0) {
            throw ( new Error('No issue request handlers registered'));
        }
        const provider = this._IssueDataProviders.get(extensionId);
        if (!provider) {
            throw ( new Error('Issue data provider not found'));
        }
        const result = await provider.provideIssueTemplate(token);
        if (!result) {
            throw ( new Error('Issue template provider returned no result'));
        }
        return result;
    }
    registerIssueUriRequestHandler(extension, provider) {
        const extensionId = extension.identifier.value;
        this._IssueUriRequestHandlers.set(extensionId, provider);
        this._proxy.$registerIssueUriRequestHandler(extensionId);
        return ( new Disposable(() => {
            this._proxy.$unregisterIssueUriRequestHandler(extensionId);
            this._IssueUriRequestHandlers.delete(extensionId);
        }));
    }
    registerIssueDataProvider(extension, provider) {
        const extensionId = extension.identifier.value;
        this._IssueDataProviders.set(extensionId, provider);
        this._proxy.$registerIssueDataProvider(extensionId);
        return ( new Disposable(() => {
            this._proxy.$unregisterIssueDataProvider(extensionId);
            this._IssueDataProviders.delete(extensionId);
        }));
    }
}
export { ExtHostIssueReporter };
