// engine/test-mocks-generator/mock-templates-b.ts — SPEC-018
// Go, JUnit, Rust, and xUnit mock template generators.
function goMockTemplate(targets, title) {
    const pkg = title.toLowerCase().replace(/\s+/g, '');
    const interfaces = targets
        .map((t) => {
        const iface = `${t}Interface`;
        return (`// Mock${t} is a testify/mock implementation of ${iface}.\n` +
            `type Mock${t} struct {\n` +
            `\tmock.Mock\n` +
            `}\n` +
            `\n` +
            `// FindByID is a mocked method on Mock${t}.\n` +
            `func (m *Mock${t}) FindByID(id string) (map[string]interface{}, error) {\n` +
            `\targs := m.Called(id)\n` +
            `\treturn args.Get(0).(map[string]interface{}), args.Error(1)\n` +
            `}`);
    })
        .join('\n\n');
    const testSetup = targets
        .map((t) => `\t\tmock${t} := new(Mock${t})\n\t\tmock${t}.On("FindByID", "1").Return(map[string]interface{}{"id": "1"}, nil)`)
        .join('\n');
    const asserts = targets.map((t) => `\t\tmock${t}.AssertExpectations(t)`).join('\n');
    return [
        `// ${title} — Go testify/mock setup`,
        `package ${pkg}_test`,
        '',
        'import (',
        '\t"testing"',
        '',
        '\t"github.com/stretchr/testify/assert"',
        '\t"github.com/stretchr/testify/mock"',
        ')',
        '',
        interfaces,
        '',
        `func Test${title.replace(/\s+/g, '')}WithMocks(t *testing.T) {`,
        '\tt.Run("calls dependency correctly", func(t *testing.T) {',
        testSetup,
        '',
        '\t\t// Act: call the function under test with mock',
        '\t\tresult := true // TODO: replace with actual call',
        '',
        '\t\t// Assert',
        '\t\tassert.True(t, result)',
        asserts,
        '\t})',
        '}',
        '',
    ].join('\n');
}
function junitMockTemplate(targets, title) {
    const cls = title.replace(/\s+/g, '');
    const fields = targets
        .map((t) => `    @Mock\n    private ${t} ${t.charAt(0).toLowerCase() + t.slice(1)};`)
        .join('\n\n');
    const stubs = targets
        .map((t) => {
        const field = t.charAt(0).toLowerCase() + t.slice(1);
        return `        when(${field}.findById("1")).thenReturn(Optional.of(new Object()));`;
    })
        .join('\n');
    return [
        `// ${title} — JUnit 5 + Mockito mock setup`,
        'package com.example.tests;',
        '',
        'import org.junit.jupiter.api.Test;',
        'import org.junit.jupiter.api.extension.ExtendWith;',
        'import org.mockito.InjectMocks;',
        'import org.mockito.Mock;',
        'import org.mockito.junit.jupiter.MockitoExtension;',
        'import java.util.Optional;',
        '',
        'import static org.mockito.Mockito.*;',
        'import static org.junit.jupiter.api.Assertions.*;',
        '',
        `@ExtendWith(MockitoExtension.class)`,
        `class ${cls}Test {`,
        '',
        fields,
        '',
        '    @Test',
        `    void shouldCallMockedDependency() {`,
        '        // Arrange',
        stubs,
        '',
        '        // Act',
        '        boolean result = true; // TODO: call class under test',
        '',
        '        // Assert',
        '        assertTrue(result);',
        targets
            .map((t) => `        verify(${t.charAt(0).toLowerCase() + t.slice(1)}, times(1)).findById("1");`)
            .join('\n'),
        '    }',
        '}',
        '',
    ].join('\n');
}
function rustMockTemplate(targets, title) {
    const snakeTitle = title.toLowerCase().replace(/\s+/g, '_');
    const mocks = targets
        .map((t) => `#[cfg_attr(test, mockall::automock)]\n` +
        `pub trait ${t}Trait {\n` +
        `    fn find_by_id(&self, id: &str) -> Result<String, String>;\n` +
        `}`)
        .join('\n\n');
    const testSetup = targets
        .map((t) => {
        const varName = t
            .replace(/([A-Z])/g, '_$1')
            .toLowerCase()
            .replace(/^_/, '');
        return (`        let mut mock_${varName} = Mock${t}Trait::new();\n` +
            `        mock_${varName}\n` +
            `            .expect_find_by_id()\n` +
            `            .with(mockall::predicate::eq("1"))\n` +
            `            .times(1)\n` +
            `            .returning(|_| Ok("found".to_string()));`);
    })
        .join('\n\n');
    return [
        `// ${title} — Rust mockall mock setup`,
        '#[cfg(test)]',
        'mod tests {',
        '    use super::*;',
        '',
        mocks
            .split('\n')
            .map((l) => `    ${l}`)
            .join('\n'),
        '',
        '    #[test]',
        `    fn test_${snakeTitle}_with_mock() {`,
        testSetup
            .split('\n')
            .map((l) => `    ${l}`)
            .join('\n'),
        '',
        '        // Act: call function under test with mock',
        '        let result = true; // TODO: replace with actual call',
        '',
        '        // Assert',
        '        assert!(result);',
        '    }',
        '}',
        '',
    ].join('\n');
}
function xunitMockTemplate(targets, title) {
    const cls = title.replace(/\s+/g, '');
    const fields = targets
        .map((t) => `    private readonly Mock<I${t}> _mock${t} = new();`)
        .join('\n');
    const setups = targets
        .map((t) => `        _mock${t}.Setup(x => x.FindByIdAsync("1")).ReturnsAsync(new object());`)
        .join('\n');
    const verifies = targets
        .map((t) => `        _mock${t}.Verify(x => x.FindByIdAsync("1"), Times.Once);`)
        .join('\n');
    return [
        `// ${title} — xUnit + Moq mock setup`,
        'using Xunit;',
        'using Moq;',
        'using System.Threading.Tasks;',
        '',
        `public class ${cls}Tests {`,
        '    // Moq mock instances — created per-test for isolation',
        fields,
        '',
        '    [Fact]',
        `    public async Task Should_Call_Mocked_Dependency() {`,
        '        // Arrange',
        setups,
        '',
        '        // Act',
        '        var result = true; // TODO: call class under test',
        '',
        '        // Assert',
        '        Assert.True(result);',
        verifies,
        '    }',
        '}',
        '',
    ].join('\n');
}
/** Additional mock template functions for compiled languages. */
export const MOCK_TEMPLATES_B = {
    'go-test': goMockTemplate,
    junit: junitMockTemplate,
    testng: junitMockTemplate,
    'cargo-test': rustMockTemplate,
    xunit: xunitMockTemplate,
    nunit: xunitMockTemplate,
};
//# sourceMappingURL=mock-templates-b.js.map