package com.utopiaindustries.dao.ctp;

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

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

public class BundleRowMapper implements RowMapper<Bundle> {
	public Bundle mapRow( ResultSet rs, int rowNum ) throws SQLException {
		Bundle bundle = new Bundle();
		bundle.setId( rs.getLong( "id" ) );
		bundle.setItemId( rs.getLong( "item_id" ) );
		bundle.setSku( rs.getString( "sku" ) );
		bundle.setWrapQuantity( rs.getBigDecimal( "wrap_quantity" ) );
		bundle.setBarcode( rs.getString( "barcode" ) );
		bundle.setType( rs.getString( "type" ) );
		bundle.setCreatedBy( rs.getString( "created_by" ) );
		bundle.setProduction(rs.getBigDecimal("production"));
		if ( rs.getTimestamp( "created_at" ) != null ) {
			bundle.setCreatedAt( rs.getTimestamp( "created_at" ).toLocalDateTime() );
		}
		bundle.setJobCardId( rs.getLong( "job_card_id" ) );
		bundle.setMasterBundleId( rs.getLong( "master_bundle_id" ) );
		return bundle;
	}
}