def get_leave_days_by_id(id):  # noqa: E501
    """Find LeaveDays by ID

    Returns a single LeaveDays. # noqa: E501

    :param id: ID of LeaveDays to return
    :type id: int

    :rtype: LeaveDays
    """
    found = dao.get(id)
    if found is None:
        return ErrorApiResponse.LeaveDaysNotFoundError(id=id), 404
    return to_dto(found)
def update_leave_days_by_id(id, body):  # noqa: E501
    """Updates a LeaveDays in the system with form data. Role write:leave_days must be granted

     # noqa: E501

    :param id: ID of LeaveDays to return
    :type id: int
    :param body: LeaveDays object that needs to be updated in the system
    :type body: dict | bytes

    :rtype: LeaveDays
    """
    found = dao.get(id)
    if found is None:
        return ErrorApiResponse.LeaveDaysNotFoundError(id=id), 404
    if connexion.request.is_json:
        body = LeaveDays.from_dict(connexion.request.get_json())  # noqa: E501
    delta = body.end_date - body.start_date
    if delta.days < 0:
        return ErrorApiResponse.LeaveDaysPeriodError(body.start_date,
                                                     body.end_date), 409
    # check already exists
    duplicate = find_leave_days_by(body.employee_id, body.start_date,
                                   body.end_date)
    if len(duplicate) > 1 or (len(duplicate) == 1 and duplicate[0].id != id):
        return ErrorApiResponse.LeaveDaysExistError(body.employee_id,
                                                    body.start_date,
                                                    body.end_date), 409
    # check employee exist
    employee = employee_dao.get(body.employee_id)
    if employee is None:
        return ErrorApiResponse.EmployeeNotFoundError(body.employee_id), 404
    # check rules
    conflict = rules.check_rules(body.employee_id, body.start_date,
                                 body.end_date, id)
    if len(conflict) > 0:
        return ApiResponseConflict(code=5000,
                                   type='leave days',
                                   message='Restrictions are violated',
                                   details=conflict), 409
    found.employee_id = body.employee_id
    found.start_date = body.start_date
    found.end_date = body.end_date
    found.leave_days = body.leave_days
    try:
        dao.persist(found)
        return get_leave_days_by_id(id)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='leave days'), 500
def delete_leave_days(id):  # noqa: E501
    """Deletes a LeaveDays. Role write:leave_days must be granteds

     # noqa: E501

    :param id: LeaveDays id to delete
    :type id: int

    :rtype: ApiResponse
    """
    found = dao.get(id)
    if found is None:
        return ErrorApiResponse.LeaveDaysNotFoundError(id=id), 404
    try:
        dao.delete(found)
        return 'Successful operation', 204
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='leave days'), 500
def find_leave_days_by_date(employeeId, leave_date):  # noqa: E501
    """Finds unique LeaveDays by employee and leave date

     # noqa: E501

    :param employeeId: Employee id to filter by
    :type employeeId: int
    :param leave_date: Leave date to filter by
    :type leave_date: str

    :rtype: LeaveDays
    """
    try:
        if leave_date and isinstance(leave_date, str):
            leave_date = util.deserialize_date(leave_date)
        found = dao.find_by_date(employeeId, leave_date)
        if found is None:
            return ErrorApiResponse.LeaveDaysNotFoundError(
                employee_id=employeeId, leave_date=leave_date), 404
        return to_dto(found)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='leave days'), 500