package org.artgasmator.data.dao.impl;

import java.util.List;

import org.artgasmator.data.dao.AlbumGenreDao;
import org.artgasmator.data.rowmapper.AlbumGenreRowMapper;
import org.artgasmator.model.AlbumGenre;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;

public class AlbumGenreDaoImpl extends AbstractDao implements AlbumGenreDao {

	private AlbumGenreRowMapper albumGenreRowMapper = new AlbumGenreRowMapper();
	
	public List<AlbumGenre> loadGenres() {
		
		String sql = "SELECT * FROM genre";
		return jdbcTemplate.getJdbcOperations().query(sql, albumGenreRowMapper);
	}


	public void createGenre(AlbumGenre albumGenre) {
		
		MapSqlParameterSource params = new MapSqlParameterSource();
		params.addValue("name", albumGenre.getGenreName()).
				addValue("description", albumGenre.getGenreDescription());
		
		jdbcTemplate.update("INSERT INTO genre(genre_name, genre_description) VALUES (:name, :description)", params);
		
	}

	public void deleteGenre(Integer genreId) {
		
		MapSqlParameterSource params = new MapSqlParameterSource();
		params.addValue("genreId", genreId);
		
		jdbcTemplate.update("DELETE FROM genre WHERE genre_id = :genreId", params);
		
	}
	
}
