using AyCode.Services.Nav;
using AyCode.Services.Nav.Ekaer.Models;

namespace AyCode.Services.Tests.Nav;

/// <summary>
/// Az EKÁER generált modellekre <c>partial class</c>-szal ráhúzott Nav base-interfészek ellenőrzése
/// (<c>EkaerNavAdapters.cs</c>). Igazolja, hogy a <see cref="NavReportServiceBase{TRequest,TResponse}"/>
/// az interfészeken keresztül helyesen éri el a generált típusok mezőit.
/// </summary>
[TestClass]
public class EkaerAdapterTests
{
    [TestMethod]
    public void UserHeader_TaxNumber_MapsToVatNumber_BothWays()
    {
        var user = new UserHeaderType { VatNumber = "12345678" };
        Assert.AreEqual("12345678", ((INavUserHeader)user).TaxNumber, "olvasás: TaxNumber → VATNumber");

        ((INavUserHeader)user).TaxNumber = "87654321";
        Assert.AreEqual("87654321", user.VatNumber, "írás: TaxNumber → VATNumber");
    }

    [TestMethod]
    public void BaseResult_IsSuccess_OnlyWhenFuncCodeOk()
    {
        Assert.IsTrue(((INavResult)new BaseResultType { FuncCode = FunctionCodeType.Ok }).IsSuccess);
        Assert.IsFalse(((INavResult)new BaseResultType { FuncCode = FunctionCodeType.Error }).IsSuccess);
        Assert.IsFalse(((INavResult)new BaseResultType { FuncCode = FunctionCodeType.Warning }).IsSuccess);
    }

    [TestMethod]
    public void BaseResult_ExposesReasonCodeAndMessage()
    {
        var result = new BaseResultType
        {
            FuncCode = FunctionCodeType.Error,
            Msg = "hiba történt",
        };
        var nav = (INavResult)result;
        Assert.AreEqual("hiba történt", nav.Message);
        Assert.IsNotNull(nav.ReasonCode); // a reasonCode enum ToString-je
    }

    [TestMethod]
    public void BasicRequest_ExposesHeaderAndUserViaInterface()
    {
        var request = new ManageTradeCardsRequest
        {
            Header = new BasicHeaderType { RequestId = "R1" },
            User = new UserHeaderType { User = "u1" },
        };

        var nav = (INavRequest)request;
        Assert.AreSame(request.Header, nav.RequestHeader);
        Assert.AreSame(request.User, nav.UserHeader);
        Assert.AreEqual("R1", nav.RequestHeader.RequestId);
        Assert.AreEqual("u1", nav.UserHeader.User);
    }

    [TestMethod]
    public void BasicResponse_ExposesResultViaInterface()
    {
        var response = new ManageTradeCardsResponse { Result = new BaseResultType { FuncCode = FunctionCodeType.Ok } };
        Assert.AreSame(response.Result, ((INavResponse)response).Result);
        Assert.IsTrue(((INavResponse)response).Result.IsSuccess);
    }
}
