using System.Collections;
using System.Runtime.CompilerServices;
using Chocco.Services.Availability.Core.Exceptions;
using Chocco.Services.Availability.Core.ValueObjects;
namespace Chocco.Services.Availability.Core.Entities;
public class Resource : AggregateRoot
{
private ISet<string> _tags = new HashSet<string>();
private ISet<Reservation> _reservations = new HashSet<Reservation>();
public IEnumerable<string> Tags
{
get => _tags;
private set => _tags = new HashSet<string>(value);
}
public IEnumerable<Reservation> Reservations
{
get => _reservations;
private set => _reservations = new HashSet<Reservation>(value);
}
public Resource(AggregateId id, IEnumerable<string> tags, IEnumerable<Reservation>? reservations = null, int version = 0)
{
var enumerable = tags.ToList();
ValidateTags(enumerable);
Id = id;
Tags = enumerable;
Reservations = reservations ?? Enumerable.Empty<Reservation>();
Version = version;
}
private static void ValidateTags(IEnumerable<string> tags)
{
var enumerable = tags.ToList();
if (tags is null || !enumerable.Any())
{
throw new MissingResourceTagsException();
}
if (enumerable.Any(string.IsNullOrWhiteSpace))
{
throw new InvalidResourceTagsException();
}
}
}
using System.Collections;
using System.Runtime.CompilerServices;
using Chocco.Services.Availability.Core.Exceptions;
using Chocco.Services.Availability.Core.ValueObjects;
namespace Chocco.Services.Availability.Core.Entities;
public class Resource : AggregateRoot
{
private ISet<string> _tags = new HashSet<string>();
private ISet<Reservation> _reservations = new HashSet<Reservation>();
public IEnumerable<string> Tags
{
get => _tags;
private set => _tags = new HashSet<string>(value);
}
public IEnumerable<Reservation> Reservations
{
get => _reservations;
private set => _reservations = new HashSet<Reservation>(value);
}
public Resource(AggregateId id, IEnumerable<string> tags, IEnumerable<Reservation>? reservations = null, int version = 0)
{
var enumerable = tags.ToList();
ValidateTags(enumerable);
Id = id;
Tags = enumerable;
Reservations = reservations ?? Enumerable.Empty<Reservation>();
Version = version;
}
private static void ValidateTags(IEnumerable<string> tags)
{
var enumerable = tags.ToList();
if (tags is null || !enumerable.Any())
{
throw new MissingResourceTagsException();
}
if (enumerable.Any(string.IsNullOrWhiteSpace))
{
throw new InvalidResourceTagsException();
}
}
}