using ChatService.Domain.Contracts;
using FluentAssertions;
using Xunit;

namespace ChatService.UnitTests.Domain.Contracts;

/// <summary>
/// EN: Unit tests for IAIService interface and related DTOs.
/// VI: Unit tests cho IAIService interface và các DTOs liên quan.
/// </summary>
public class AIServiceContractTests
{
    [Fact]
    public void ChatMessage_ShouldCreateWithAllProperties()
    {
        // Arrange
        var role = "user";
        var content = "Hello AI!";
        var timestamp = DateTime.UtcNow;

        // Act
        var message = new ChatMessage(role, content, timestamp);

        // Assert
        message.Role.Should().Be(role);
        message.Content.Should().Be(content);
        message.Timestamp.Should().Be(timestamp);
    }

    [Theory]
    [InlineData("user")]
    [InlineData("assistant")]
    [InlineData("system")]
    public void ChatMessage_ShouldAcceptValidRoles(string role)
    {
        // Arrange & Act
        var message = new ChatMessage(role, "Test content", DateTime.UtcNow);

        // Assert
        message.Role.Should().Be(role);
    }

    [Fact]
    public void AIServiceOptions_ShouldHaveDefaultValues()
    {
        // Arrange & Act
        var options = new AIServiceOptions();

        // Assert
        options.Provider.Should().Be("OpenAI");
        options.Model.Should().Be("gpt-4");
        options.MaxHistoryMessages.Should().Be(20);
        options.MaxTokens.Should().Be(1000);
        options.Temperature.Should().BeApproximately(0.7f, 0.001f);
        options.SystemPrompt.Should().NotBeNullOrEmpty();
    }

    [Fact]
    public void AIServiceOptions_SectionName_ShouldBeAI()
    {
        // Assert
        AIServiceOptions.SectionName.Should().Be("AI");
    }

    [Fact]
    public void AIServiceOptions_ShouldAllowCustomConfiguration()
    {
        // Arrange & Act
        var options = new AIServiceOptions
        {
            Provider = "AzureOpenAI",
            Model = "gpt-3.5-turbo",
            MaxHistoryMessages = 50,
            MaxTokens = 2000,
            Temperature = 0.5f,
            SystemPrompt = "Custom prompt"
        };

        // Assert
        options.Provider.Should().Be("AzureOpenAI");
        options.Model.Should().Be("gpt-3.5-turbo");
        options.MaxHistoryMessages.Should().Be(50);
        options.MaxTokens.Should().Be(2000);
        options.Temperature.Should().BeApproximately(0.5f, 0.001f);
        options.SystemPrompt.Should().Be("Custom prompt");
    }
}
