using System.Linq.Expressions;
using Monitoring.Core.Domain.CheckListManagement;

namespace Monitoring.Features.CheckListManagement;

public sealed record CheckListTemplateItemModel(
	Guid Id,
	int Index,
	List<CheckListTemplateItemTranslationModel> Translations
)
{
	public static CheckListTemplateItemModel FromEntity(CheckListTemplateItem entity)
	{
		return new(
			entity.Id.Value,
			entity.Index,
			[.. entity.Translations.Select(CheckListTemplateItemTranslationModel.FromEntity)]
		);
	}

	public static Expression<Func<CheckListTemplateItem, CheckListTemplateItemModel>> Projection =>
		x =>
			new(
				x.Id.Value,
				x.Index,
				x.Translations.AsQueryable()
					.Select(CheckListTemplateItemTranslationModel.Projection)
					.ToList()
			);
};
