package com.utopiaindustries.dao.ctp;

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

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

public class FinishedItemRowMapper implements RowMapper<FinishedItem> {
	public FinishedItem mapRow( ResultSet rs, int rowNum ) throws SQLException {
		FinishedItem finishedItem = new FinishedItem();
		finishedItem.setId( rs.getLong( "id" ) );
		finishedItem.setItemId( rs.getLong( "item_id" ) );
		finishedItem.setSku( rs.getString( "sku" ) );
		finishedItem.setBarcode( rs.getString( "barcode" ) );
		if ( rs.getTimestamp( "created_at" ) != null ) {
			finishedItem.setCreatedAt( rs.getTimestamp( "created_at" ).toLocalDateTime() );
		}
		if ( rs.getTimestamp( "operation_date" ) != null ) {
			finishedItem.setOperationDate( rs.getTimestamp( "operation_date" ).toLocalDateTime() );
		}
		finishedItem.setCreatedBy( rs.getString( "created_by" ) );
		finishedItem.setJobCardId( rs.getLong("job_card_id") );
		finishedItem.setIsQa( rs.getBoolean("is_qa"));
		finishedItem.setStitchedItemId( rs.getLong("stitched_item_id" ) );
		finishedItem.setIsSegregated( rs.getBoolean( "is_segregated") );
		finishedItem.setQaStatus( rs.getString("qa_status" ) );
		finishedItem.setPackaging( rs.getBoolean("is_packed" ) );
		finishedItem.setStore( rs.getBoolean("is_store" ) );
		return finishedItem;
	}
}