using Monitoring.Core.Domain.AssetManagement;
using Monitoring.Core.Domain.Primitives;

namespace Monitoring.Core.Domain.EventManagement;

/// <summary>
/// Событие.
/// </summary>
public class Event
{
	/// <summary>
	/// Событие.
	/// </summary>
	public EventId Id { get; } = default!;
	public EventCodeId CodeId { get; } = default!;
	public EventCode Code { get; } = default!;
	public AreaIndex AreaIndex { get; } = new(0);
	public ZoneIndex ZoneIndex { get; } = new(0);

	public DateTime ReceivedAt { get; } = DateTime.UtcNow;
	public DateTime CreatedAt { get; } = DateTime.UtcNow;

	public AssetId AssetId { get; } = default!;
	public Asset Asset { get; } = default!;

	public List<Fault> Faults { get; } = [];
	public List<Alarm> Alarms { get; } = [];

	public static Event Create(
		EventId id,
		EventCodeId codeId,
		AreaIndex areaIndex,
		ZoneIndex zoneIndex,
		AssetId assetId,
		DateTime receivedAt,
		DateTime createdAt
	)
	{
		return new Event(id, codeId, areaIndex, zoneIndex, assetId, receivedAt, createdAt);
	}

	private Event(
		EventId id,
		EventCodeId codeId,
		AreaIndex areaIndex,
		ZoneIndex zoneIndex,
		AssetId assetId,
		DateTime receivedAt,
		DateTime createdAt
	)
	{
		Id = id;
		CodeId = codeId;
		AreaIndex = areaIndex;
		ZoneIndex = zoneIndex;
		AssetId = assetId;
		ReceivedAt = receivedAt;
		CreatedAt = createdAt;
	}

	protected Event() { }
}
