using System;
using System.Collections.Generic;
namespace TINK.Model.Bikes.BikeInfoNS.BikeNS
{
/// Count of wheels.
/// Numeric values of enum must match count of wheels
public enum WheelType
{
Mono = 1,
Two = 2,
Trike = 3,
Quad = 4
}
/// Type of bike.
public enum TypeOfBike
{
Allround = 0,
Cargo = 1,
City = 2,
}
/// Holds the model of lock.
public enum LockModel
{
ILockIt, // haveltec GbmH Brandenburg, Germany bluetooth lock
BordComputer, // Teilrad BC
Sigo, // Sigo Gmbh Darmstadt, Germany bike lock
}
/// Holds the type of lock.
public enum LockType
{
Backend, // Backend, i.e. COPRI controls lock (open, close, ...)
Bluethooth, // Lock is controlled.
}
public class Bike : IEquatable
{
///
/// Constructs a bike.
///
/// Unique id of bike.
public Bike(
string id,
LockModel lockModel,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null)
{
WheelType = wheelType;
TypeOfBike = typeOfBike;
LockModel = lockModel;
Id = id;
Description = description;
}
///
/// Holds the unique id of the bike;
///
public string Id { get; }
///
/// Holds the count of wheels.
///
public WheelType? WheelType { get; }
///
/// Holds the type of bike.
///
public TypeOfBike? TypeOfBike { get; }
/// Gets the model of the lock.
public LockModel LockModel { get; private set; }
/// Holds the description of the bike.
public string Description { get; }
/// Compares two bike object.
/// Object to compare with.
/// True if bikes are equal.
public override bool Equals(object obj)
{
var l_oBike = obj as Bike;
if (l_oBike == null)
{
return false;
}
return Equals(l_oBike);
}
/// Converts the instance to text.
public new string ToString()
{
return WheelType == null || TypeOfBike == null
? $"Id={Id}{(!string.IsNullOrEmpty(Description) ? $", {Description}" : "")}"
: $"Id={Id}{(WheelType != null ? $", wheel(s)={WheelType}" : string.Empty)}{(TypeOfBike != null ? $"type={TypeOfBike}" : "")}.";
}
/// Compares two bike object.
/// Object to compare with.
/// True if bikes are equal.
public bool Equals(Bike other)
{
return other != null &&
Id == other.Id &&
WheelType == other.WheelType &&
TypeOfBike == other.TypeOfBike
&& Description == other.Description;
}
/// Compares two bike object.
/// Object to compare with.
/// True if bikes are equal.
public static bool operator ==(Bike bike1, Bike bike2)
{
return EqualityComparer.Default.Equals(bike1, bike2);
}
/// Compares two bike object.
/// Object to compare with.
/// True if bikes are equal.
public static bool operator !=(Bike bike1, Bike bike2)
{
return !(bike1 == bike2);
}
///
/// Generates hash code for bike object.
///
///
public override int GetHashCode()
{
var hashCode = -390870100;
hashCode = hashCode * -1521134295 + Id.GetHashCode();
hashCode = hashCode * -1521134295 + WheelType?.GetHashCode() ?? 0;
hashCode = hashCode * -1521134295 + TypeOfBike?.GetHashCode() ?? 0;
hashCode = hashCode * -1521134295 + Description?.GetHashCode() ?? 0;
return hashCode;
}
}
}