using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
///
/// Define a step of the preparation of a recipe.
///
[DataContract(Name = "preparation-step")]
public class PreparationStep : IEquatable
{
#region Attributes
private string _description = "";
#endregion
#region Properties
///
/// The order of this step in the preparation of the meal.
///
[DataMember(Name = "order")]
public int Order { get; init; }
///
/// The description of the task the user need to do for this step of the preparation.
/// Set to "No description." when the value passed is null, empty or contain white spaces.
///
[DataMember(Name = "description")]
public string Description
{
get => _description;
private set
{
if (string.IsNullOrWhiteSpace(value))
_description = "No description.";
else
_description = value;
}
}
#endregion
#region Constructors
///
/// Construct a new step of preparation.
///
/// The number of the order in preparation
/// The description of the task
public PreparationStep(int order, string description = "")
{
Order = order;
Description = description;
}
#endregion
#region Methods
public virtual bool Equals(PreparationStep? other)
{
if (other == null) return false;
if (other == this) return true;
return Order.Equals(other.Order) && Description.Equals(other.Description);
}
public override bool Equals(object? obj)
{
var item = obj as PreparationStep;
if (item == null) return false;
return Equals(obj);
}
public override int GetHashCode()
{
return Order.GetHashCode() + Description.GetHashCode();
}
public override string ToString()
{
return $"{Order}- {Description}";
}
#endregion
}
}