using Baya.Domain.Entities.Verification;

namespace Baya.Test.Foundation.Verification;

/// <summary>
/// Helpers for the verification handler/aggregator tests. Entity ids have a protected setter (they are
/// assigned by EF on save); these set them via reflection so a mocked repository can return graphs with
/// stable ids without a real DbContext.
/// </summary>
internal static class VerificationTestSupport
{
    public static T WithId<T>(this T entity, long id)
    {
        var setter = typeof(T).GetProperty("Id")!.GetSetMethod(nonPublic: true)!;
        setter.Invoke(entity, [id]);
        return entity;
    }

    public static VerificationStepType StepType(long id, string code, bool automated, bool required = true)
        => new VerificationStepType
        {
            Code = code,
            DisplayName = code,
            IsAutomated = automated,
            IsRequired = required,
            IsActive = true,
            SortOrder = (int)id
        }.WithId(id);

    public static VerificationStep Step(long id, VerificationStepType type, VerificationStepStatus status)
        => new VerificationStep
        {
            StepTypeId = type.Id,
            StepType = type,
            Status = status,
            IsAutomated = type.IsAutomated
        }.WithId(id);
}
