import { get, post } from "../../editor/services/serviceHelper";
const MODEL_IMPORT_EXCLUDED_PROVIDER_TYPES = new Set([
    "vertex",
    "azure-openai",
]);
export function providerSupportsModelImport(provider, providerTypes) {
    if (!provider)
        return false;
    const providerType = provider.type.toLowerCase();
    if (MODEL_IMPORT_EXCLUDED_PROVIDER_TYPES.has(providerType))
        return false;
    return providerTypes.some((type) => type.providerId.toLowerCase() === providerType);
}
export function getImportableProviders(providers, providerTypes) {
    return providers.filter((provider) => providerSupportsModelImport(provider, providerTypes));
}
export const setupWizardService = {
    async getProviderTypes() {
        const result = await get("/parhelia/setup/GetProviderTypes");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get provider types");
        }
        return result.data;
    },
    async applyBaseSettings() {
        const result = await post("/parhelia/setup/ApplyBaseSettings", {});
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to apply base settings");
        }
        return result.data;
    },
    async getProviders() {
        const result = await get("/parhelia/setup/GetProviders");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get providers");
        }
        return result.data;
    },
    async createProvider(request) {
        const result = await post("/parhelia/setup/CreateProvider", request);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to create provider");
        }
        return result.data.id;
    },
    async deleteProvider(providerId) {
        const result = await post("/parhelia/setup/DeleteProvider", { providerId });
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to delete provider");
        }
    },
    async getInstalledModels() {
        const result = await get("/parhelia/setup/GetInstalledModels");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get installed models");
        }
        return result.data;
    },
    async updateModel(request) {
        const result = await post("/parhelia/setup/UpdateModel", request);
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to update model");
        }
    },
    async getInstalledAgents() {
        const result = await get("/parhelia/setup/GetInstalledAgents");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get installed agents");
        }
        return result.data;
    },
    async createAgent(request) {
        const result = await post("/parhelia/setup/CreateAgent", request);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to create agent");
        }
        return result.data.id;
    },
    async getJavaScriptTools() {
        const result = await get("/parhelia/setup/GetJavaScriptTools");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get JavaScript tools");
        }
        return result.data;
    },
    async createJavaScriptTool(request) {
        const result = await post("/parhelia/setup/CreateJavaScriptTool", request);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to create JavaScript tool");
        }
        return result.data.id;
    },
    async createMcpServer(request) {
        const result = await post("/parhelia/setup/CreateMcpServer", request);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to create MCP server");
        }
        return result.data.id;
    },
    async deleteJavaScriptTool(javaScriptToolId) {
        const result = await post("/parhelia/setup/DeleteJavaScriptTool", { javaScriptToolId });
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to delete JavaScript tool");
        }
    },
    async getJavaScriptToolAgent(javaScriptToolId) {
        const result = await get(`/parhelia/setup/JavaScriptToolAgent?javaScriptToolId=${encodeURIComponent(javaScriptToolId)}`);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details ||
                result.summary ||
                "Failed to load JavaScript tool assistant");
        }
        return result.data;
    },
    async resetJavaScriptToolAgent(javaScriptToolId) {
        const result = await post("/parhelia/setup/ResetJavaScriptToolAgent", { javaScriptToolId });
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details ||
                result.summary ||
                "Failed to restart JavaScript tool assistant");
        }
        return result.data;
    },
    async getEmbeddingsModels() {
        const result = await get("/parhelia/setup/GetEmbeddingsModels");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get embeddings models");
        }
        return result.data;
    },
    async getChatModels() {
        const result = await get("/parhelia/setup/GetChatModels");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get chat models");
        }
        return result.data;
    },
    async getImageModels() {
        const result = await get("/parhelia/setup/GetImageModels");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get image models");
        }
        return result.data;
    },
    async setEmbeddingsConfig(request) {
        const result = await post("/parhelia/setup/SetEmbeddingsConfig", request);
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to set embeddings config");
        }
    },
    async getEmbeddingsConfig() {
        const result = await get("/parhelia/setup/GetEmbeddingsConfig");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get embeddings config");
        }
        return result.data;
    },
    async setValidationConfig(request) {
        const result = await post("/parhelia/setup/SetValidationConfig", request);
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to set validation config");
        }
    },
    async getValidationConfig() {
        const result = await get("/parhelia/setup/GetValidationConfig");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get validation config");
        }
        return result.data;
    },
    async getSearchSettingsInfo() {
        const result = await get("/parhelia/setup/GetSearchSettingsInfo");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details ||
                result.summary ||
                "Failed to get search settings info");
        }
        return result.data;
    },
    async createSearchSettingsItem() {
        const result = await post("/parhelia/setup/CreateSearchSettingsItem", {});
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details ||
                result.summary ||
                "Failed to create search settings item");
        }
        return result.data.id;
    },
    async createModel(request) {
        const result = await post("/parhelia/setup/CreateModel", request);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to create model");
        }
        return result.data.id;
    },
    async getProviderModels(providerId) {
        const result = await get(`/parhelia/setup/GetProviderModels?providerId=${encodeURIComponent(providerId)}`);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get provider models");
        }
        return result.data;
    },
    async upsertProviderModels(request) {
        const result = await post("/parhelia/setup/UpsertProviderModels", request);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to upsert provider models");
        }
        return result.data;
    },
    async getToolFunctions() {
        const result = await get("/parhelia/setup/GetToolFunctions");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get tool functions");
        }
        return result.data;
    },
    async getMcpToolFunctions() {
        const result = await get("/parhelia/setup/GetMcpToolFunctions");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get MCP tool functions");
        }
        return result.data;
    },
    async installMcpTools() {
        const result = await post("/parhelia/setup/InstallMcpTools", {});
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to install MCP tools");
        }
        return result.data;
    },
    async updateTools() {
        const result = await post("/parhelia/setup/UpdateTools", {});
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to update tools");
        }
        return result.data;
    },
    async getToolConfiguration(functionName) {
        const result = await get(`/parhelia/setup/GetToolConfiguration?functionName=${encodeURIComponent(functionName)}`);
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get tool configuration");
        }
        return result.data;
    },
    async applyToolConfiguration(request) {
        const result = await post("/parhelia/setup/ApplyToolConfiguration", request);
        if (result.type !== "success") {
            throw new Error(result.details ||
                result.summary ||
                "Failed to apply tool configuration");
        }
    },
    async applyToolDefaults() {
        const result = await post("/parhelia/setup/ApplyToolDefaults", {});
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to apply tool defaults");
        }
        return result.data;
    },
    async createSettingsItem() {
        const result = await post("/parhelia/setup/CreateSettingsItem", {});
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to create settings item");
        }
        return result.data.id;
    },
    async setDefaultModels(request) {
        const result = await post("/parhelia/setup/SetDefaultModels", request);
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to set default models");
        }
    },
    async getDefaultModels() {
        const result = await get("/parhelia/setup/GetDefaultModels");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get default models");
        }
        return result.data;
    },
    async completeSetup() {
        const result = await post("/parhelia/setup/CompleteSetup", {});
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to complete setup");
        }
    },
    async getSettingsExists() {
        const result = await get("/parhelia/setup/GetSettingsExists");
        if (result.type !== "success") {
            throw new Error(result.details || result.summary || "Failed to check settings");
        }
        return result.data ?? false;
    },
    /**
     * Gets a summary of setup status. This endpoint is accessible to all authenticated users,
     * not just admins, and returns only boolean/count data for status checks.
     */
    async getStatusSummary() {
        const result = await get("/parhelia/setup/GetStatusSummary");
        if (result.type !== "success" || !result.data) {
            throw new Error(result.details || result.summary || "Failed to get status summary");
        }
        return result.data;
    },
};
//# sourceMappingURL=setupWizardService.js.map