package com.utopiaindustries.dao.ctp;

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

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

public class StitchingOfflineItemRowMapper implements RowMapper<StitchingOfflineItem> {

    @Override
    public StitchingOfflineItem mapRow(ResultSet rs, int i) throws SQLException {
        StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem();
        stitchingOfflineItem.setId( rs.getLong( "id" ) );
        stitchingOfflineItem.setItemId( rs.getLong( "item_id" ) );
        stitchingOfflineItem.setSku( rs.getString( "sku" ) );
        stitchingOfflineItem.setBarcode( rs.getString( "barcode" ) );
        stitchingOfflineItem.setBundleId(rs.getLong("bundle_id"));
        if ( rs.getTimestamp( "created_at" ) != null ) {
            stitchingOfflineItem.setCreatedAt( rs.getTimestamp( "created_at" ).toLocalDateTime() );
        }
        if ( rs.getTimestamp( "qc_done_at" ) != null ) {
            stitchingOfflineItem.setQcDoneAt( rs.getTimestamp( "qc_done_at" ).toLocalDateTime() );
        }
        stitchingOfflineItem.setCreatedBy( rs.getString( "created_by" ) );
        stitchingOfflineItem.setJobCardId( rs.getLong("job_card_id") );
        stitchingOfflineItem.setIsQa( rs.getBoolean("is_qa"));
        stitchingOfflineItem.setInlineReceived( rs.getBoolean("inline_received"));
        stitchingOfflineItem.setQaStatus( rs.getString("qa_status" ) );
        stitchingOfflineItem.setQaRemarks( rs.getString("qa_remarks") );
        return stitchingOfflineItem;
    }
}
