using BuildingBlock.Catalog.Contracts.Conventions;
using BuildingBlock.Catalog.Contracts.Responses;
using BuildingBlock.Inventory.Contracts.Conventions;
using BuildingBlock.Inventory.Contracts.Responses;
using Furniture.Domain.Contracts;
using Furniture.Domain.Decisions;

namespace Furniture.Domain.UnitTests;

public class FurnitureAvailabilityDecisionServiceTests
{
    [Fact]
    public void BuildCatalogRequest_WhenCalled_UsesFurnitureIdAsProductId()
    {
        var service = new FurnitureAvailabilityDecisionService();

        var request = service.BuildCatalogRequest(new FurnitureAvailabilityDecisionRequest("FUR-001", "corr-001"));

        Assert.Equal("FUR-001", request.ProductId);
        Assert.Equal("corr-001", request.Envelope.CorrelationId);
    }

    [Fact]
    public void BuildInventoryRequest_WhenCorrelationMissing_GeneratesCorrelation()
    {
        var service = new FurnitureAvailabilityDecisionService();

        var request = service.BuildInventoryRequest(new FurnitureAvailabilityDecisionRequest("FUR-001", string.Empty));

        Assert.Equal("FUR-001", request.ItemCode);
        Assert.NotEmpty(request.Envelope.CorrelationId);
    }

    [Fact]
    public void ComposeResponse_WhenCalled_UsesCatalogAndInventoryValues()
    {
        var service = new FurnitureAvailabilityDecisionService();
        var request = new FurnitureAvailabilityDecisionRequest("FUR-001", "corr-001");
        var catalog = new ProductContractResponse(
            new CatalogContractEnvelope("1.0.0", "corr-001"),
            "FUR-001",
            "Chair");
        var inventory = new InventoryItemLookupResponse(
            new InventoryContractEnvelope("1.0.0", "corr-001"),
            "FUR-001",
            12);

        var response = service.ComposeResponse(request, catalog, inventory);

        Assert.Equal("FUR-001", response.FurnitureId);
        Assert.Equal("Chair", response.DisplayName);
        Assert.Equal(12, response.QuantityAvailable);
    }
}
