package net.sevecek.dailyplanet;

import java.sql.*;
import java.util.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.jdbc.core.*;
import org.springframework.stereotype.*;

@Component
public class PrevodnikTridyClanek implements RowMapper<Clanek> {

    @Autowired
    private RowMapper<Autor> prevodniTridyAutor;

    @Override
    public Clanek mapRow(ResultSet rs, int rowNum) throws SQLException {
        Autor autor = null;
        if (rs.getString("autor.id") != null) {
            autor = prevodniTridyAutor.mapRow(rs, rowNum);
        }
        UUID clanekId = UUID.fromString(rs.getString("clanek.Clanek_ID"));
        String nazev = rs.getString("clanek.Nazev");
        int cisloRevize = rs.getInt("clanek.cisloRevize");
        return new Clanek(clanekId, nazev, autor, cisloRevize);
    }
}
