using Monitoring.Core.Domain.EventManagement;
using Monitoring.Core.Domain.UserPrimitives;

namespace Monitoring.Core.Domain.CallManagement;

/// <summary>
/// Звонок.
/// </summary>
public class Call
{
	/// <summary>
	/// Идентификатор.
	/// </summary>
	public CallId Id { get; } = null!;

	/// <summary>
	/// Тревога, по которой совершён звонок.
	/// </summary>
	public AlarmScope AlarmScope { get; } = null!;

	/// <summary>
	/// ИД тревоги.
	/// </summary>
	public AlarmScopeId AlarmScopeId { get; } = null!;

	/// <summary>
	/// Оператор (звонивший).
	/// </summary>
	public User Caller { get; } = null!;

	/// <summary>
	/// ИД оператора (звонившего).
	/// </summary>
	public UserId CallerId { get; } = null!;

	/// <summary>
	/// Дата/время начала звонка.
	/// </summary>
	public DateTime StartedAt { get; } = DateTime.UtcNow;

	/// <summary>
	/// Ответственный (адресат).
	/// </summary>
	public ResponsiblePerson ResponsiblePerson { get; } = null!;

	/// <summary>
	/// ИД ответственного (адресата).
	/// </summary>
	public Guid ResponsiblePersonId { get; } = Guid.Empty;

	/// <summary>
	/// Подтверждение реальности тревоги.
	/// </summary>
	public bool IsConfirmedRealAlarm { get; set; }

	/// <summary>
	/// Комментарий оператора.
	/// </summary>
	public CallCommentary Commentary { get; set; } = null!;

	/// <summary>
	/// Результат звонка.
	/// </summary>
	public CallResult Result { get; set; }

	public static Call Create(
		AlarmScopeId alarmScopeId,
		UserId callerId,
		Guid responsiblePersonId,
		CallCommentary commentary,
		bool isConfirmedRealAlarm,
		CallResult result
	)
	{
		return new(
			new CallId(Guid.CreateVersion7()),
			alarmScopeId,
			callerId,
			responsiblePersonId,
			commentary,
			isConfirmedRealAlarm,
			result
		);
	}

	private Call(
		CallId id,
		AlarmScopeId alarmScopeId,
		UserId callerId,
		Guid responsiblePersonId,
		CallCommentary commentary,
		bool isConfirmedRealAlarm,
		CallResult result
	)
	{
		Id = id;
		AlarmScopeId = alarmScopeId;
		CallerId = callerId;
		ResponsiblePersonId = responsiblePersonId;
		Commentary = commentary;
		IsConfirmedRealAlarm = isConfirmedRealAlarm;
		Result = result;
	}

	/// <summary>
	/// Constructor for EF.
	/// </summary>
	protected Call() { }
}
