using Newtonsoft.Json;
using System;
using System.Runtime.Serialization;
namespace TINK.Model.Bikes.Bike.CopriLock
{
/// Locking states.
public enum LockingState
{
/// App is not connected to lock.
UnknownDisconnected,
/// Lock is closed.
Closed,
/// Lock is closing.
Closing,
/// Lock is open.
Open,
/// Lock is opening.
Opening
}
[DataContract]
public class LockInfo : ILockInfo
{
/// Locking state of bluetooth lock.
[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(JsonConvert.SerializeObject(lockInfo));
}
private readonly LockInfo LockInfo = new LockInfo();
public LockingState State { get => LockInfo.State; set => LockInfo.State = value; }
public LockInfo Build() => LockInfo;
}
}
}