using Monitoring.Core.Domain.AssetManagement;
using Monitoring.Core.Domain.OrganizationManagement;

namespace Monitoring.Core.Domain.AssetGroupManagement;

public class AssetGroup
{
	public AssetGroupId Id { get; } = default!;
	public AssetGroupName Name { get; private set; } = default!;
	public bool HasPBX { get; private set; }

	public OrganizationId OrganizationId { get; } = default!;
	public Organization Organization { get; } = default!;

	public List<Asset> Assets { get; private set; } = [];

	public List<AssetGroup> Children { get; } = [];
	public AssetGroup? Parent { get; }
	public AssetGroupId? ParentId { get; private set; }

	public List<Access> Accesses { get; } = [];

	public void SetParent(AssetGroupId? parentId)
	{
		ParentId = parentId;
	}

	public static AssetGroup Create(AssetGroupName name, OrganizationId organizationId, bool hasPBX)
	{
		return new AssetGroup(new(Guid.NewGuid()), name, organizationId, hasPBX);
	}

	public static AssetGroup Create(
		AssetGroupId id,
		AssetGroupName name,
		OrganizationId organizationId,
		bool hasPBX
	)
	{
		return new AssetGroup(id, name, organizationId, hasPBX);
	}

	public void Update(AssetGroupName assetGroupName, bool hasPBX)
	{
		Name = assetGroupName;
		HasPBX = hasPBX;
	}

	private AssetGroup(
		AssetGroupId id,
		AssetGroupName name,
		OrganizationId organizationId,
		bool hasPBX
	)
	{
		Id = id;
		Name = name;
		OrganizationId = organizationId;
		HasPBX = hasPBX;
	}

	protected AssetGroup() { }
}
