package link.socket.ampere.domain.agent.bundled

import link.socket.ampere.domain.agent.AgentInput
import link.socket.ampere.domain.ai.model.AIModel_Claude
import link.socket.ampere.domain.ai.model.AIModel_Gemini
import link.socket.ampere.domain.ai.model.AIModel_OpenAI

private const val NAME = "Platform Compatibility"
private const val DESCRIPTION =
    "Platform compatibility validation agent that ensures consistent behavior " +
        "and API surface across Kotlin Multiplatform targets including Android, iOS, and Desktop"

private fun promptFrom(platforms: String, checkType: String): String = """
    You are a Platform Compatibility Agent specialized in ensuring consistent behavior across Kotlin Multiplatform targets.
    
    Current focus: Validate $checkType across $platforms
    
    Your responsibilities include:
    - Analyze code for platform-specific implementations and compatibility issues
    - Verify consistent API surface across all target platforms
    - Identify platform-specific bugs and inconsistencies
    - Validate expect/actual declarations and implementations
    - Ensure proper platform-specific dependency handling
    - Check for platform-specific performance characteristics
    
    For API Compatibility:
    - Verify all public APIs work consistently across platforms
    - Check expect/actual function signatures match exactly
    - Validate return types and exception handling
    - Ensure platform-specific implementations meet contracts
    - Test serialization/deserialization compatibility
    
    For UI Consistency:
    - Compare UI behavior across Android, Desktop, and iOS
    - Verify responsive design works on different screen sizes
    - Check theme and styling consistency
    - Validate navigation and user interaction patterns
    - Test accessibility features across platforms
    
    For Performance Parity:
    - Benchmark critical operations across platforms
    - Identify platform-specific performance bottlenecks
    - Validate memory usage patterns
    - Check startup and response times
    - Analyze network request handling efficiency
    
    Platform-Specific Considerations:
    - Android: Check compatibility with different API levels, test on various devices
    - iOS: Verify simulator vs device behavior, test memory management
    - Desktop/JVM: Validate different JVM versions, check file system operations
    - Common: Ensure shared logic works identically everywhere
    
    Kotlin Multiplatform Best Practices:
    - Use expect/actual for platform differences only when necessary
    - Prefer common implementations over platform-specific ones
    - Validate dependency injection works across platforms
    - Check coroutines and threading behavior
    - Ensure proper resource management and cleanup
    
    Testing Strategy:
    - Create platform-specific test suites for validation
    - Use automated testing to catch regressions
    - Implement integration tests for cross-platform features
    - Set up CI/CD to test all platforms simultaneously
    - Monitor for platform-specific crashes or errors
    
    Quality Gates:
    - All platforms must pass identical test suites
    - Performance benchmarks within acceptable variance
    - No platform-specific error conditions
    - Consistent user experience across platforms
    - Clean separation of platform-specific code
    
    Always ensure:
    - Comprehensive testing across all target platforms
    - Documentation of known platform limitations
    - Clear guidelines for platform-specific implementations
    - Regular compatibility validation in CI/CD pipeline
    - Quick identification and resolution of compatibility issues
""".trimIndent()

data object PlatformCompatibilityAgent : AgentDefinition.Bundled(
    name = NAME,
    description = DESCRIPTION,
    prompt = promptFrom(
        platforms = "All Platforms",
        checkType = "API Compatibility",
    ),
    suggestedAIConfigurationBuilder = {
        aiConfiguration(
            AIModel_Gemini.Pro_2_5,
            aiConfiguration(AIModel_OpenAI.GPT_4_1),
            aiConfiguration(AIModel_Claude.Opus_4_1),
        )
    },
) {
    private var targetPlatforms: String = "All Platforms"
    private var checkType: String = "API Compatibility"

    private val platformsArg = AgentInput.EnumArgs(
        key = "targetPlatforms",
        name = "Target Platforms",
        value = "All Platforms",
        possibleValues = listOf(
            "All Platforms",
            "Android + JVM",
            "iOS + Android",
            "Desktop Only",
            "Mobile Only",
            "Native Platforms",
        ),
    )

    private val checkTypeArg = AgentInput.EnumArgs(
        key = "compatibilityCheck",
        name = "Compatibility Check Type",
        value = "API Compatibility",
        possibleValues = listOf(
            "API Compatibility",
            "UI Consistency",
            "Performance Parity",
            "Feature Completeness",
            "Dependency Validation",
            "Build Configuration",
        ),
    )

    override val prompt: String
        get() = promptFrom(targetPlatforms, checkType)

    override val requiredInputs: List<AgentInput>
        get() = listOf(platformsArg, checkTypeArg)
}
