//
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
//
using System.Text.Json.Serialization;
using Astral.Services.Dtos;
namespace Astral.ApiServer.Models;
///
/// Heartbeat contents.
///
public class HeartbeatModel
{
///
/// True if connected.
///
[JsonPropertyName("connected")]
public bool? Connected { get; set; }
///
/// Path.
///
[JsonPropertyName("path")]
public string Path { get; set; }
///
/// Domain id.
///
[JsonPropertyName("domain_id")]
public string DomainId { get; set; }
///
/// Place id.
///
[JsonPropertyName("place_id")]
public string PlaceId { get; set; }
///
/// Network address.
///
[JsonPropertyName("network_address")]
public string NetworkAddress { get; set; }
///
/// Network port.
///
[JsonPropertyName("network_port")]
public int? NetworkPort { get; set; }
///
/// Node id.
///
[JsonPropertyName("node_id")]
public string NodeId { get; set; }
///
/// Availability.
///
[JsonPropertyName("availability")]
public string Availability { get; set; }
///
/// Convert this model to .
///
/// Instance of .
public UserLocationHeartbeatDto ToUserLocationHeartbeat()
{
var result = new UserLocationHeartbeatDto()
{
Connected = Connected,
Path = Path,
NetworkAddress = NetworkAddress,
NetworkPort = NetworkPort,
Availability = Availability
};
if (!string.IsNullOrEmpty(DomainId))
{
if (Guid.TryParse(DomainId, out var guid))
{
result.DomainId = guid;
}
else
{
result.DomainId = null;
}
}
if (!string.IsNullOrEmpty(PlaceId))
{
if (Guid.TryParse(PlaceId, out var guid))
{
result.PlaceId = guid;
}
else
{
PlaceId = null;
}
}
if (!string.IsNullOrEmpty(NodeId))
{
if (Guid.TryParse(NodeId, out var guid))
{
result.NodeId = guid;
}
else
{
result.NodeId = null;
}
}
return result;
}
}