using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UniversityAgregationComposition
{
    class University
    {
     //departments is a composition.
    //departments lifetime controlled by lifetime of Company
    private Dictionary<string, Department> departments = new Dictionary<string, Department>();

    public University(string[] departmentsToCreate)
    {
        Console.WriteLine("Creating the company and its departments");
        foreach(string departmentToCreate in departmentsToCreate)
        {
            departments.Add(departmentToCreate, new Department{Name = departmentToCreate});
        }
    }

    ~University()  // destructor
    {
        // cleanup statements...
        departments.Clear();
        departments = null;
    }

    public Department this[string departmentName]
    {
        get { return departments[departmentName]; }
    }

    public void ReassignAndCloseDepartmentEmployees(string departmentToCloseName, string reassignmentDepartmentName)
    {
        Department fromDepartment = this[departmentToCloseName];
        Department toDepartment = this[reassignmentDepartmentName];
        foreach (Professor employee in fromDepartment.GetProfessorsByDepartement())
        {
            toDepartment.Add(employee);
        }
        departments.Remove(departmentToCloseName);
    }
    }
}
