using Monitoring.Core.Domain.AssetManagement;

namespace Monitoring.Core.Domain.ServiceOrganizationManagement;

/// <summary>
  /// Обслуживающая организация
/// </summary>
public class ServiceOrganization : IAuditable
{
  /// <summary>
  /// Идентификатор организации
  /// </summary>
        public ServiceOrganizationId Id { get; set; } = default!;

  /// <summary>
  /// Название организации
  /// </summary>
  public ServiceOrganizationName Name { get; set; } = default!;

  /// <summary>
  /// Дата создания
  /// </summary>
  public DateTime CreatedAt { get; set; } = default!;

  /// <summary>
  /// Дата последнего обновления
  /// </summary>
  public DateTime UpdatedAt { get; set; } = default!;

  /// <summary>
  /// Таймштамп (для контроля версий)
  /// </summary>
  public byte[] TimeStamp { get; set; } = Guid.NewGuid().ToByteArray();




  /// <summary>
  /// Список активов, обслуживаемых организацией
  /// </summary>
  public List<Asset> Assets { get; } = [];

 
  public static ServiceOrganization Create(ServiceOrganizationName name)
  {
    return new ServiceOrganization(
      new ServiceOrganizationId(Guid.NewGuid()),
      name,
      Guid.NewGuid().ToByteArray() // Явно задаём TimeStamp
    );
  }

	 public void UpdateAuditInfo()
    {
        UpdatedAt = DateTime.UtcNow;
        TimeStamp = Guid.NewGuid().ToByteArray();
    }  

	private ServiceOrganization(
        ServiceOrganizationId id,
        ServiceOrganizationName name,
        byte[] timeStamp)
    {
        Id = id;
        Name = name;
        CreatedAt = DateTime.UtcNow;
        UpdatedAt = DateTime.UtcNow;
        TimeStamp = timeStamp;
    }

  protected ServiceOrganization()
    {
        TimeStamp = Guid.NewGuid().ToByteArray();
        CreatedAt = DateTime.UtcNow;
        UpdatedAt = DateTime.UtcNow;
    }

}