package com.pas.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.pas.dao.ParkingPlaceDao;
import com.pas.model.ParkingPlace;
import com.pas.model.User;

@Repository
public class ParkingPlaceDaoImpl implements ParkingPlaceDao {
	@Autowired
	private SessionFactory session;
	
	@Override
	public void add(ParkingPlace parkingPlace) {
		session.getCurrentSession().save(parkingPlace);
	}
	
	@Override
	public void edit(ParkingPlace parkingPlace) {
		session.getCurrentSession().update(parkingPlace);
	}
	
	@Override
	public void delete(int parkingPlaceId) {
		session.getCurrentSession().delete(parkingPlaceId);
	}
	
	@Override
	public ParkingPlace getParkingPlace(int parkingPlaceId) {
		return (ParkingPlace) session.getCurrentSession().get(ParkingPlace.class, parkingPlaceId);
	}
	
	@Override
	public List<ParkingPlace> getAllParkingPlace() {
		return (List<ParkingPlace>) session.getCurrentSession().createQuery("from " + ParkingPlace.class.getName()).list();
	}

	@Override
	public List<ParkingPlace> getParkingPlaceByUser(User user) {
		return (List<ParkingPlace>) session.getCurrentSession().createQuery("from " + ParkingPlace.class.getName() + "where user_app_id = '" + user.getId() + "'").list();
	}
}