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

namespace Monitoring.Features.Assets;

public record AssetModel(
	Guid Id,
	string Name,
	string Description,
	string Comment,
	Guid OrganizationId,
	IEnumerable<Guid> GroupIds,
	float? Latitude,
	float? Longitude,
	string Country,
	string Region,
	string City,
	string Street,
	string House,
	string Building,
	string Apartment,
	string GateCode,
	string IntercomCode,
	string OwnerName,
	string OwnerPassword,
	string OwnerPhone1,
	string OwnerPhone2,
	string IdentificationPassword,
	string DuressPassword,
	Guid? ServiceOrganizationId,
	string? ServiceOrganizationName,
	bool IsOnline,
	string RowVersion,
	string? Imei,
	DateTime? LastStatusChange
)
{
	public static readonly Expression<Func<Asset, AssetModel>> FromEntity =
		entity => new AssetModel(
			entity.Id.Value,
			entity.Name.Value,
			entity.Description.Value,
			entity.Comment.Value,
			entity.OrganizationId.Value,
			entity.Groups.Select(x => x.Id.Value),
			entity.Coordinates.Latitude,
			entity.Coordinates.Longitude,
			entity.Address.Country,
			entity.Address.Region,
			entity.Address.City,
			entity.Address.Street,
			entity.Address.House,
			entity.Address.Building,
			entity.Address.Apartment,
			entity.Address.GateCode,
			entity.Address.IntercomCode,
			entity.Owner.Name,
			entity.Owner.Password,
			entity.Owner.Phone1,
			entity.Owner.Phone2,
			entity.Passwords.IdentificationPassword,
			entity.Passwords.DuressPassword,
			entity.ServiceOrganizationId!.Value,
			entity.ServiceOrganization!.Name.Value,
			entity.IsOnline,
			entity.RowVersion.Length > 0 ? Convert.ToBase64String(entity.RowVersion) : "",
			entity.Imei.Value,
			entity.LastStatusChange
		);
};
