sharee.bike-App/LockItShared/Model/Bikes/Bike/CopriLock/LockInfo.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

88 lines
1.9 KiB
C#

using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace TINK.Model.Bikes.BikeInfoNS.CopriLock
{
/// <summary> Locking states. </summary>
public enum LockingState
{
/// <summary> App is not connected to lock.</summary>
UnknownDisconnected,
/// <summary> Lock is closed. </summary>
Closed,
/// <summary> Lock is closing. </summary>
Closing,
/// <summary> Lock is open. </summary>
Open,
/// <summary> Lock is opening. </summary>
Opening
}
[DataContract]
public class LockInfo : ILockInfo
{
/// <summary> Locking state of bluetooth lock. </summary>
[DataMember]
public LockingState State { get; private set; } = LockingState.UnknownDisconnected;
public override bool Equals(object obj) => this.Equals(obj as LockInfo);
public bool Equals(LockInfo other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
if (this.GetType() != other.GetType()) return false;
return ToString() == other.ToString();
}
public override int GetHashCode()
{
return ToString().GetHashCode();
}
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
public static bool operator ==(LockInfo lhs, LockInfo rhs)
{
if (Object.ReferenceEquals(lhs, null))
return Object.ReferenceEquals(rhs, null) ? true /*null == null = true*/: false;
return lhs.Equals(rhs);
}
public static bool operator !=(LockInfo lhs, LockInfo rhs)
{
return !(lhs == rhs);
}
public class Builder
{
public Builder(LockInfo lockInfo = null)
{
if (lockInfo == null)
{
return;
}
LockInfo = JsonConvert.DeserializeObject<LockInfo>(JsonConvert.SerializeObject(lockInfo));
}
private readonly LockInfo LockInfo = new LockInfo();
public LockingState State { get => LockInfo.State; set => LockInfo.State = value; }
public LockInfo Build() => LockInfo;
}
}
}