using System;
using System.Collections.Generic;
namespace TINK.Model.Bike
{
/// Count of wheels.
public enum WheelType
{
Mono = 0,
Two = 1,
Trike = 2,
}
/// Type of bike.
public enum TypeOfBike
{
Allround = 0,
Cargo = 1,
Citybike = 2,
}
public class Bike : IEquatable
{
///
/// Constructs a bike.
///
/// Provider for current date time to calculate remainig time on demand for state of type reserved.
///
/// Unique id of bike.
/// Name of station where bike is located, null if bike is on the road.
public Bike(
int p_iId,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null)
{
WheelType = wheelType;
TypeOfBike = typeOfBike;
Id = p_iId;
Description = description;
}
///
/// Holds the unique id of the bike;
///
public int Id { get; }
///
/// Holds the count of wheels.
///
public WheelType? WheelType { get; }
///
/// Holds the type of bike.
///
public TypeOfBike? TypeOfBike { get; }
/// 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;
}
}
}