/**
 * @license
 * Copyright 2026 HopCode Team
 * SPDX-License-Identifier: Apache-2.0
 */
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { modelCommand } from './modelCommand.js';
import {} from './types.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import { AuthType, } from '@hoptrendy/hopcode-core';
// Helper function to create a mock config
function createMockConfig(contentGeneratorConfig) {
    return {
        getContentGeneratorConfig: vi.fn().mockReturnValue(contentGeneratorConfig),
    };
}
describe('modelCommand', () => {
    let mockContext;
    beforeEach(() => {
        mockContext = createMockCommandContext();
        vi.clearAllMocks();
    });
    it('should have the correct name and description', () => {
        expect(modelCommand.name).toBe('model');
        expect(modelCommand.description).toBe('Switch the model for this session (--fast for suggestion model)');
    });
    it('should return error when config is not available', async () => {
        mockContext.services.config = null;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'message',
            messageType: 'error',
            content: 'Configuration not available.',
        });
    });
    it('should return error when content generator config is not available', async () => {
        const mockConfig = createMockConfig(null);
        mockContext.services.config = mockConfig;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'message',
            messageType: 'error',
            content: 'Content generator configuration not available.',
        });
    });
    it('should return error when auth type is not available', async () => {
        const mockConfig = createMockConfig({
            model: 'test-model',
            authType: undefined,
        });
        mockContext.services.config = mockConfig;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'message',
            messageType: 'error',
            content: 'Authentication type not available.',
        });
    });
    it('should return dialog action for HOPCODE_OAUTH auth type', async () => {
        const mockConfig = createMockConfig({
            model: 'test-model',
            authType: AuthType.HOPCODE_OAUTH,
        });
        mockContext.services.config = mockConfig;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'dialog',
            dialog: 'model',
        });
    });
    it('should return dialog action for USE_OPENAI auth type', async () => {
        const mockConfig = createMockConfig({
            model: 'test-model',
            authType: AuthType.USE_OPENAI,
        });
        mockContext.services.config = mockConfig;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'dialog',
            dialog: 'model',
        });
    });
    it('should return dialog action for unsupported auth types', async () => {
        const mockConfig = createMockConfig({
            model: 'test-model',
            authType: 'UNSUPPORTED_AUTH_TYPE',
        });
        mockContext.services.config = mockConfig;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'dialog',
            dialog: 'model',
        });
    });
    it('should handle undefined auth type', async () => {
        const mockConfig = createMockConfig({
            model: 'test-model',
            authType: undefined,
        });
        mockContext.services.config = mockConfig;
        const result = await modelCommand.action(mockContext, '');
        expect(result).toEqual({
            type: 'message',
            messageType: 'error',
            content: 'Authentication type not available.',
        });
    });
    describe('non-interactive mode', () => {
        it('should return current model without triggering dialog when no args', async () => {
            mockContext = createMockCommandContext({
                executionMode: 'non_interactive',
                services: {
                    config: {
                        getContentGeneratorConfig: vi.fn().mockReturnValue({
                            model: 'qwen-max',
                            authType: AuthType.HOPCODE_OAUTH,
                        }),
                        getModel: vi.fn().mockReturnValue('qwen-max'),
                    },
                },
            });
            const result = await modelCommand.action(mockContext, '');
            expect(result).toEqual({
                type: 'message',
                messageType: 'info',
                content: expect.stringContaining('qwen-max'),
            });
            expect(result.type).toBe('message');
        });
        it('should return current fast model without triggering dialog for --fast no args', async () => {
            mockContext = createMockCommandContext({
                executionMode: 'non_interactive',
                invocation: { args: '--fast' },
                services: {
                    config: {
                        getContentGeneratorConfig: vi.fn().mockReturnValue({
                            model: 'qwen-max',
                            authType: AuthType.HOPCODE_OAUTH,
                        }),
                        getModel: vi.fn().mockReturnValue('qwen-max'),
                    },
                    settings: {
                        merged: { fastModel: 'qwen-turbo' },
                    },
                },
            });
            const result = await modelCommand.action(mockContext, '--fast');
            expect(result).toEqual({
                type: 'message',
                messageType: 'info',
                content: expect.stringContaining('qwen-turbo'),
            });
        });
    });
});
//# sourceMappingURL=modelCommand.test.js.map