export const ollamaModelTemplate = {
    provider: 'ollama',
    label: 'New Ollama Model',
    model: 'llama3',
    description: 'A local Ollama model configuration',
    baseUrl: 'http://localhost:11434',
    connection: {},
    settings: {
        temperature: 0.7,
        num_ctx: 2048
    }
};
export const ollamaModelDefinition = {
    id: 'ollama',
    displayName: 'Ollama',
    badgeClassName: 'bg-slate-200 text-slate-800',
    defaultModelTemplate: ollamaModelTemplate,
    viewFields: [
        {
            label: 'Model',
            render: (model) => model.model || 'Not set'
        },
        {
            label: 'Endpoint',
            render: (model) => {
                const connectionBaseUrl = typeof model.connection?.baseUrl === 'string' ? model.connection?.baseUrl : undefined;
                return model.baseUrl || connectionBaseUrl || 'http://localhost:11434';
            }
        }
    ],
    form: {
        schema: [
            ['label', {
                    type: 'string',
                    label: 'Model Name',
                    required: true,
                    description: 'Display label for this Ollama configuration'
                }],
            ['model', {
                    type: 'string',
                    label: 'Ollama Model',
                    required: true,
                    description: 'Ollama model identifier (e.g. llama3, mistral)'
                }],
            ['description', {
                    type: 'string',
                    label: 'Description',
                    description: 'Optional description for this model configuration'
                }],
            ['baseUrl', {
                    type: 'string',
                    label: 'Base URL',
                    description: 'Ollama API endpoint (default http://localhost:11434)'
                }],
            ['temperature', {
                    type: 'number',
                    label: 'Temperature',
                    minimum: 0,
                    maximum: 2,
                    description: 'Sampling temperature'
                }],
            ['num_ctx', {
                    type: 'integer',
                    label: 'Context Tokens',
                    minimum: 256,
                    maximum: 16384,
                    description: 'Maximum context tokens'
                }]
        ],
        getInitialValues: (model) => ({
            label: model.label,
            model: model.model,
            description: model.description ?? '',
            baseUrl: (() => {
                if (typeof model.baseUrl === 'string' && model.baseUrl.trim().length > 0) {
                    return model.baseUrl.trim();
                }
                const connectionBaseUrl = typeof model.connection?.baseUrl === 'string' ? model.connection.baseUrl.trim() : '';
                return connectionBaseUrl || 'http://localhost:11434';
            })(),
            temperature: model.settings?.temperature ?? 0.7,
            num_ctx: model.settings?.num_ctx ?? 2048
        }),
        transformSubmit: (values, existingModel) => {
            const baseUrl = typeof values.baseUrl === 'string' && values.baseUrl.trim().length > 0
                ? values.baseUrl.trim()
                : undefined;
            const temperature = typeof values.temperature === 'number' ? values.temperature : undefined;
            const numCtxRaw = typeof values.num_ctx === 'number' ? values.num_ctx : undefined;
            const numCtx = typeof numCtxRaw === 'number' && Number.isFinite(numCtxRaw) ? Math.max(256, Math.min(numCtxRaw, 16384)) : undefined;
            return {
                provider: existingModel.provider,
                label: values.label,
                model: values.model,
                description: values.description || undefined,
                baseUrl,
                connection: {
                    ...(existingModel.connection ?? {}),
                    ...(baseUrl ? { baseUrl } : {})
                },
                settings: {
                    ...(existingModel.settings ?? {}),
                    ...(temperature !== undefined ? { temperature } : {}),
                    ...(numCtx !== undefined ? { num_ctx: numCtx } : {})
                }
            };
        },
        submitButtonText: 'Update Model'
    }
};
