using BuildingDirectory.Model;
namespace BuildingDirectory;
///
/// Represents a simple building information system
///
public sealed class BuildingInformation
{
private readonly MyDictionary> _companiesPerFloor;
///
/// Creates a new instance with the supplied building information
///
///
public BuildingInformation(MyDictionary> companiesPerFloor)
{
_companiesPerFloor = companiesPerFloor;
}
///
/// Returns all floors in the building
///
/// A list of available floors
public List GetFloorSelection() => _companiesPerFloor.GetKeys();
///
/// Returns all companies residing on a specific floor.
/// If floor is not available null is returned.
///
/// The floor to check
/// A list of names of companies residing on the provided floor
public List? GetCompaniesOnFloor(Floor floor)
{
_companiesPerFloor.TryGetValue(floor, out MyDictionary? companies);
return companies?.GetKeys();
}
///
/// Returns the company identified by floor and company name.
/// If the specified company is not found null is returned.
///
/// Floor to look at
/// Name of the requested company
/// Company information if found; null otherwise
public Company? GetCompany(Floor floor, string companyName)
{
//Needed to declare here, else you get an initialization error
Company? company = null;
_companiesPerFloor.TryGetValue(floor, out MyDictionary? companies);
companies?.TryGetValue(companyName, out company);
return company;
}
}