using adas_core.Domain.Enums; using MongoDB.Bson; using Newtonsoft.Json; namespace adas_core.Domain.Models.MongoModels; /// /// Represents a relay class that provides functionality for forwarding or passing through data, commands, or notifications between components. /// /// /// This class serves as an intermediary mechanism, commonly used to decouple producers and consumers of information. /// public class Relay { public ObjectId Id { get; set; } public RelayEnum.Type Type { get; set; } = RelayEnum.Type.Door; public string? Driver { get; init; } public string Ip { get; init; } = string.Empty; public int Port { get; init; } public int RelayNumber { get; init; } = 1; public string? RelayName { get; init; } public int Total { get; init; } = 1; public int RefreshTime { get; set; } = 60; public bool Open { get; set; } public RelayEnum.Status Status { get; set; } = RelayEnum.Status.NotInitialized; public string? Username { get; init; } public string? Password { get; init; } public RelayEnum.Mode Mode { get; set; } = RelayEnum.Mode.OpenedOnClosedOff; public int? RebootDelay { get; set; } public bool Cache { get; set; } = true; public bool InUse { get; private set; } public RelayEnum.Status? ManualRelayStatus { get; set; } /// /// Determines whether the current instance is equal to another by comparing all of their properties (Driver, Ip, Port, RelayNumber, RelayName, Total, Username, and Password). /// /// The other instance to compare against the current one. /// true if all properties of both relays match; otherwise, false. public bool Equals(Relay other) { return Driver == other.Driver && Ip == other.Ip && Port == other.Port && RelayNumber == other.RelayNumber && RelayName == other.RelayName && Total == other.Total && Username == other.Username && Password == other.Password; } /// /// Returns a JSON string representation of the current object, serializing all its public properties via JsonConvert. /// /// A JSON-formatted string that represents the current object. public override string ToString() { return JsonConvert.SerializeObject(this); } }