<repo_name>sriharshakappala/incident-alerter<file_sep>/runner.rb
require './services/runner_service'

runner = RunnerService.instance()

runner.add_project('Project A')
runner.add_project('Project B')

runner.add_employee('Employee 1', '<EMAIL>', '111')
runner.add_employee('Employee 2', '<EMAIL>', '222')
runner.add_employee('Employee 3', '<EMAIL>', '333')

runner.assign_project('Project A', 'Employee 1')
runner.assign_project('Project A', 'Employee 2')
runner.assign_project('Project B', 'Employee 2')
runner.assign_project('Project B', 'Employee 3')

runner.set_level('Project A', 'Employee 1', 0)
runner.set_level('Project A', 'Employee 2', 1)
runner.set_level('Project A', 'Employee 3', 0)

runner.unset_level('Project A', 0)
runner.set_level('Project A', 'Employee 2', 3)
runner.set_level('Project A', 'Employee 3', 0)

binding.pry
pp runner.inspect
<file_sep>/models/employee.rb
require 'securerandom'

class Employee

  attr_accessor :name, :email_id, :phone_number

  def initialize name, email_id, phone_number
    @employee_id = employee_id
    @name = name
    @email_id = email_id
    @phone_number = phone_number
  end

  def employee_id
    SecureRandom.hex(10)
  end

end
<file_sep>/services/runner_service.rb
require 'singleton'
require 'pry'

require './models/project'
require './models/employee'

class RunnerService
  include Singleton

  attr_accessor :projects, :employees

  def initialize
    @projects = []
    @employees = []
  end

  def add_project name
    begin
      project = Project.new(name)
      projects << project
      response = {"status": "success"}
    rescue
    end
    pp response
  end

  def add_employee name, email_id, phone_number
    begin
      employee = Employee.new(name, email_id, phone_number)
      employees << employee
      response = {"status": "success"}
    rescue
    end
    pp response
  end

  def assign_project project_name, employee_name
    project = get_project(project_name)
    employee = get_employee(employee_name)
    if project && employee
      project.employees << employee
      response = {"status": "success"}
    end
    pp response
  end

  def set_level project_name, employee_name, level
    project = get_project(project_name)
    employee = get_employee(employee_name)
    if project && employee
      if project.escalation_matrix.values.map(&:name).include? employee_name
        response = {"status": "Employee already in escalation matrix"}
      elsif project.escalation_matrix[level].nil?
        project.escalation_matrix[level] = employee
        response = {"status": "success"}
      else
        response = {"status": "error", "message": "This level is already assigned for the project"}
      end
    end
    pp response
  end

  def unset_level project_name, level
    project = get_project(project_name)
    project.escalation_matrix.delete(level)
    response = {"status": "success"}
    pp response
  end

  private

  def get_project project_name
    return projects.find { |p| p.name == project_name }
  end

  def get_employee employee_name
    return employees.find { |e| e.name == employee_name }
  end

end
<file_sep>/models/incident.rb
require 'securerandom'

class Incident

  attr_accessor :name, :assigned_to

  def initialize name, assigned_to
    @name = name
    @assigned_to = assigned_to
  end

  def notifiy
  end

end
<file_sep>/models/project.rb
require 'securerandom'

class Project

  attr_accessor :name, :employees, :escalation_matrix, :incident

  def initialize name
    @id = project_id
    @name = name
    @employees = []
    @escalation_matrix = {}
    @incidents = []
  end

  def project_id
    SecureRandom.hex(10)
  end

  def create_incident name
    incident = Incident.new(name)
    incident.assigned_to = self.escalation_matrix
  end

end
