using CashLineERP.Application.Parties;
using CashLineERP.Contracts.Parties;
using CashLineERP.Infrastructure.Persistence.Repositories;

namespace CashLineERP.Api.Tests;

public sealed class PartyComplianceDocumentServiceQaTests
{
    [Fact]
    public void Party_Compliance_Documents_Can_Be_Recorded_And_Read_Back()
    {
        using var dbContext = QaDbContextFactory.CreateContext();

        var service = new PartyOnboardingService(new BusinessPartyRepository(dbContext));

        var document = service.RecordComplianceDocument(3, 1, new RecordBusinessPartyComplianceDocumentRequest(
            DocumentType: "tax_card",
            FileName: "tax-card.pdf",
            StorageReference: "party/1/tax-card.pdf",
            ContentType: "application/pdf",
            FileSizeBytes: 2048));

        Assert.Equal(1L, document.PartyId);
        Assert.Equal("TAX_CARD", document.DocumentType);
        Assert.Equal(3L, document.UploadedByUserId);

        var documents = service.GetComplianceDocuments(1);
        Assert.Contains(documents, entry => entry.DocumentLinkId == document.DocumentLinkId && entry.FileName == "tax-card.pdf");
    }
}
