package com.nisum.service;

import com.nisum.dao.Dao;
import com.nisum.model.Employee;
import com.nisum.model.impl.EmployeeImp;
import com.nisum.dto.EmployeeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.Optional;

import java.util.Collection;

@Service
public class EmployeeService {

  @Autowired
  @Qualifier(value = "EmployeeDao")
  private Dao employeeDao;

  public Collection<EmployeeImp> getAllEmployees() {
    return employeeDao.getAll();
  }

  public void createEmployee(EmployeeDto employeeDto){
        EmployeeImp newEmployee = new EmployeeImp();
        newEmployee.set(employeeDto.get());
        employeeDao.save(newEmployee);
  }

  public void deleteEmployee(int id){
      Optional<EmployeeImp> employee = employeeDao.getById(id);
      if (employee.isPresent()) {
          employeeDao.delete(employee.get());
      }
  }
}
