using DTOs;
using Entities;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExtensionsClassLibrairie
{///
/// define some methods to manipulate entity, model and dto lobbies :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
///
public static class LobbyExtensionMethods
{
// conversion methods
public static Lobby ToModel(this LobbyEntity l)
=> new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id);
public static Lobby ToModel(this LobbyDto l)
=> new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id);
public static LobbyDto ToDto(this Lobby l)
=> new LobbyDto { Id = l.Id, Creator = l.Creator.ToDto(), IdCreator = l.IdCreator,
Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
public static LobbyEntity ToEntity(this Lobby l)
=> new LobbyEntity { Id = l.Id, Creator = l.Creator.ToEntity(), IdCreator = l.IdCreator,
Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
// reuse other methods
public static LobbyDto ToDto(this LobbyEntity l)
=> l.ToModel().ToDto();
public static LobbyEntity ToEntity(this LobbyDto l)
=> l.ToModel().ToEntity();
// equality protocols
public static bool Equals(this Lobby l1, Lobby l2)
=> l1.Name == l2.Name && l1.IdCreator == l2.IdCreator;
// reuse other methods
public static bool Equals(this Lobby l1, LobbyDto l2)
=> l1.Equals(l2.ToModel());
public static bool Equals(this Lobby l1, LobbyEntity l2)
=> l1.Equals(l2.ToModel());
public static bool Equals(this LobbyDto l1, Lobby l2)
=> l1.ToModel().Equals(l2);
public static bool Equals(this LobbyDto l1, LobbyDto l2)
=> l1.ToModel().Equals(l2.ToModel());
public static bool Equals(this LobbyDto l1, LobbyEntity l2)
=> l1.ToModel().Equals(l2.ToModel());
public static bool Equals(this LobbyEntity l1, Lobby l2)
=> l1.ToModel().Equals(l2);
public static bool Equals(this LobbyEntity l1, LobbyDto l2)
=> l1.ToModel().Equals(l2.ToModel());
public static bool Equals(this LobbyEntity l1, LobbyEntity l2)
=> l1.ToModel().Equals(l2.ToModel());
///
/// equality protocol for a lobby
///
/// the lobby
/// an object
/// true if the lobby and the object are sames, false otherwise
public static bool Equals(this Lobby l, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o);
else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o));
else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o);
return false;
}
///
/// equality protocol for a lobby entity
///
/// the lobby entity
/// an object
/// true if the lobby entity and the object are sames, false otherwise
public static bool Equals(this LobbyEntity l, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o);
else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o));
else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o);
return false;
}
///
/// equality protocol for a lobby dto
///
/// the lobby dto
/// an object
/// true if the lobby dto and the object are sames, false otherwise
public static bool Equals(this LobbyDto l, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o);
else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o));
else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o);
return false;
}
}
}