package com.utopiaindustries.dao.ctp;

import com.utopiaindustries.model.ctp.InventoryTransactionLeg;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class InventoryTransactionLegRowMapper implements RowMapper<InventoryTransactionLeg> {
	public InventoryTransactionLeg mapRow( ResultSet rs, int rowNum ) throws SQLException {
		InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg();
		inventoryTransactionLeg.setId( rs.getLong( "id" ) );
		inventoryTransactionLeg.setTransactionId( rs.getLong( "transaction_id" ) );
		inventoryTransactionLeg.setItemId( rs.getLong( "item_id" ) );
		inventoryTransactionLeg.setSku( rs.getString( "sku" ) );
		inventoryTransactionLeg.setType( rs.getString( "type" ) );
		inventoryTransactionLeg.setQuantity( rs.getBigDecimal( "quantity" ) );
		inventoryTransactionLeg.setAccountId( rs.getInt( "account_id" ) );
		inventoryTransactionLeg.setBalance( rs.getBigDecimal( "balance" ) );
		if ( rs.getTimestamp( "transaction_leg_datetime" ) != null ) {
			inventoryTransactionLeg.setTransactionLegDateTime( rs.getTimestamp( "transaction_leg_datetime" ).toLocalDateTime() );
		}
		inventoryTransactionLeg.setParentDocumentType( rs.getString( "parent_document_type" ) );
		inventoryTransactionLeg.setParentDocumentId( rs.getLong( "parent_document_id" ) );
		inventoryTransactionLeg.setParentDocumentPieceType( rs.getString("parent_document_piece_type"));
		inventoryTransactionLeg.setJobCardId( rs.getLong("job_card_id"));
		return inventoryTransactionLeg;
	}
}