using Monitoring.Core.Domain.UserLogManagement;

namespace Monitoring.Features.Reports.Contracts;

public class LogModel
{
    public Guid EventId { get; init; }
    public DateTime CreatedAt { get; init; }
    public string? Message { get; init; }
    public int Code { get; init; }
    public bool? IsAlarm { get; init; }
    public int? AreaIndex { get; init; }
    public int? ZoneIndex { get; init; }
    public string? Username { get; init; }

    public LogModel() {}

    public LogModel(Guid eventId, DateTime createdAt, string? message, int code, bool? isAlarm, int? areaIndex, int? zoneIndex, string? username)
    {
        EventId = eventId;
        CreatedAt = createdAt;
        Message = message;
        Code = code;
        IsAlarm = isAlarm;
        AreaIndex = areaIndex;
        ZoneIndex = zoneIndex;
        Username = username;
    }

    public static LogModel FromEvent(Core.Domain.EventManagement.Event @event)
    {
        return new LogModel(
            @event.Id.Value,
            @event.CreatedAt,
            string.Empty,
            @event.Code.Value.Value,
            @event.Code.IsActive,
            @event.AreaIndex.Value,
            @event.ZoneIndex.Value,
            string.Empty
        );
    }

    public static LogModel FromUserLog(UserLog userLog)
    {
        return new LogModel(
            userLog.Id.Value,
            userLog.CreatedAt,
            userLog.Information.Value,
            default,
            default,
            default,
            default,
            userLog.User?.Username.Value
        );
    }
}