using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace Model
{
///
/// Define a Recipe for the preparation of a meal.
///
public class Recipe : IEquatable
{
#region Attributes
private string _title = "";
#endregion
#region Properties
///
/// The ID of the recipe - allows you to compare and/or get this item in an easier way.
///
public int Id { get; init; }
///
/// The Title of the recipe.
/// Set to "No title." when the value passed is null, empty or contain white spaces.
///
public string Title
{
get => _title;
set
{
if (string.IsNullOrWhiteSpace(value))
_title = "No title.";
else
_title = value;
}
}
///
/// The steps of the preparation. See: .
///
public List PreparationSteps { get; set; }
#endregion
#region Constructors
///
/// Construct a new recipe.
///
/// The title of the recipe
/// The id of the recipe. If not given, get a new id.
/// The steps of the preparation of the meal
public Recipe(string title = "", int? id = null,
params PreparationStep[] preparationSteps)
{
Title = title;
PreparationSteps = new List(preparationSteps);
if (id == null) Id = new Random().Next();
else Id = (int)id;
}
#endregion
#region Methods
public virtual bool Equals(Recipe? other)
{
if (other == null) return false;
if (other == this) return true;
return Title.Equals(other.Title) && PreparationSteps.Equals(other.PreparationSteps);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
public override string ToString()
{
StringBuilder sb = new StringBuilder($"[Recipe n°{Id}] - {Title}\n");
foreach (PreparationStep ps in PreparationSteps)
{
sb.AppendFormat("\t* {0}\n", ps.ToString());
}
return sb.ToString();
}
#endregion
}
}