from classes.HR import get_policy
from classes.Productivity import get_role
from classes.Contact import get_employee_address

from classes.Mixin import (
  AsDictionaryMixin
)

class _EmployeeDatabase:
  def __init__(self):
    self._employees = {
      1:{
        'name': 'Mary Poppins',
        'role': 'manager'
      },
      2:{
        'name': 'John Smith',
        'role': 'secretary'
      },
      3:{
        'name': 'Kevin Bacon',
        'role': 'sales'
      },
      4:{
        'name': 'Jane Doe',
        'role': 'factory'
      },
      5:{        
        'name': 'Robin Williams',
        'role': 'secretary'
      },
    }
    # self.employee_addresses = AddressBook()

  @property
  def employees(self):
    return [Employee(id_) for id_ in sorted(self._employees)]

  def get_employee_info(self, employee_id):
    info = self._employees.get(employee_id)
    if not info:
      raise ValueError(employee_id)
    return info

class Employee(AsDictionaryMixin):
  def __init__(self, id):
    self.id = id
    info = employee_database.get_employee_info(self.id)
    self.name = info.get('name')
    self.address = get_employee_address(self.id)
    self._employ_role = get_role(info.get('role'))
    self._payroll_policy = get_policy(self.id)
    
  
  def work(self, hours):
    duties = self._employ_role.perform_duties(hours)
    print(f'Employee {self.id} - {self.name}:')
    print(f'- {duties}')
    print('')
    self._payroll_policy.track_work(hours)
  
  def calculate_payroll(self):
    return self._payroll_policy.calculate_payroll()

employee_database = _EmployeeDatabase()