package org.artgasmator.data.dao.impl;

import java.util.List;

import org.artgasmator.data.dao.ArtistLabelDao;
import org.artgasmator.data.rowmapper.ArtistLabelRowMapper;
import org.artgasmator.model.ArtistLabel;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;

public class ArtistLabelDaoImpl extends AbstractDao implements ArtistLabelDao {

	private ArtistLabelRowMapper artistLabelRowMapper = new ArtistLabelRowMapper();
	
	public List<ArtistLabel> listLabels() {
		
		String sql = "SELECT * FROM label";
		
		return jdbcTemplate.getJdbcOperations().query(sql, artistLabelRowMapper);
	}

	
	public void createArtistLabels(Integer artistId, List<Integer> labels) {
		
		String sql = "INSERT INTO artist_label(artist_id, label_id) VALUES(:artistId, :labelId)";
		
		for (Integer label : labels) {
			MapSqlParameterSource params = new MapSqlParameterSource();
			params.addValue("artistId", artistId);
			params.addValue("labelId", label);
			
			jdbcTemplate.update(sql, params);
		}
		
	}

}
