using System; using TINK.Model.Bikes.Bike.BluetoothLock; namespace TINK.Model.Bike.BluetoothLock { public class LockInfoMutable : ILockInfoMutable { /// Lock info object. private LockInfo LockInfo { get; set; } /// Constructs a bluetooth lock info object. /// Id of lock must always been known when constructing an lock info object. public LockInfoMutable( int id, Guid guid, byte[] userKey, byte[] adminKey, byte[] seed, LockingState state) { LockInfo = new LockInfo.Builder() { Id = id, Guid = guid, UserKey = userKey, AdminKey = adminKey, Seed = seed, State = state }.Build(); } public int Id => LockInfo.Id; /// Changes during runtime: Can be unknown when set from copri and chang to a valid value when set from lock. public Guid Guid { get => LockInfo.Guid; set => LockInfo = new LockInfo.Builder(LockInfo) { Guid = value }.Build(); } public byte[] Seed => LockInfo.Seed; public byte[] UserKey => LockInfo.UserKey; public byte[] AdminKey => LockInfo.AdminKey; public LockingState State { get => LockInfo.State; set => LockInfo = new LockInfo.Builder(LockInfo) { State = value }.Build(); } /// Holds the percentage of lock battery. public double BatteryPercentage { get; set; } = double.NaN; /// Loads lock info object from values. public void Load(int id, Guid guid, byte[] seed, byte[] userKey, byte[] adminKey) { LockInfo = new LockInfo.Builder(LockInfo) { Id = id, Guid = guid, Seed = seed, UserKey = userKey, AdminKey = adminKey}.Build(); } } }