using System.Linq.Expressions;

using Monitoring.Core.Domain.AssetManagement;

namespace Monitoring.Features.Reports.Contracts;

public static class Properties
{
	private const string Id = "id";
	private const string Name = "name";
	private const string HasFaults = "hasFaults";
	private const string HasAlarms = "hasAlarms";
	private const string Description = "description";
	private const string Address = "address";
	private const string Groups = "groups";

	private static readonly string[] PropertiesList = [
		Id,
		Name,
		HasFaults,
		Description,
		Address,
		Groups,
	];

	private static readonly Dictionary<string, Expression<Func<Asset, object>>> Map = new()
	{
		[Id] = x => x.Id,
		[Name] = x => x.Name,
		[HasFaults] = x => x.Events.Any(x => x.Faults.Count != 0),
		[HasAlarms] = x => x.Events.Any(x => x.Alarms.Count != 0),
		[Description] = x => x.Description,
		[Address] = x => $"{x.Address.Country}, {x.Address.City}, {x.Address.Street}, {x.Address.House}/{x.Address.Building}", // TODO: доделать нормально
		[Groups] = x => string.Join(", ", x.Groups.Select(x => x.Name)),
	};

	public static bool IsInList(string property)
	{
		return PropertiesList.Contains(property);
	}

	public static Expression<Func<Asset, object>> GetMap(string property)
	{
		return Map[property];
	}
}