package com.utopiaindustries.dao.ctp;

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

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

public class PurchaseOrderCTPRowMapper implements RowMapper<PurchaseOrderCTP> {
    public PurchaseOrderCTP mapRow(ResultSet rs, int rowNum) throws SQLException {
        PurchaseOrderCTP PurchaseOrderCTP = new PurchaseOrderCTP();
        PurchaseOrderCTP.setId(rs.getLong("id"));
        PurchaseOrderCTP.setPurchaseOrderCode(rs.getString("purchase_order_code"));
        PurchaseOrderCTP.setPurchaseOrderQuantity(rs.getInt("purchase_order_quantity"));
        PurchaseOrderCTP.setPurchaseOrderQuantityRequired(rs.getInt("purchase_order_quantity_required"));
        PurchaseOrderCTP.setArticleName(rs.getString("article_name"));
        if (rs.getTimestamp("created_at") != null) {
            PurchaseOrderCTP.setCreatedAt(rs.getTimestamp("created_at").toLocalDateTime());
        }
        PurchaseOrderCTP.setCreatedBy(rs.getString("created_by"));
        PurchaseOrderCTP.setStatus(rs.getString("status"));
        PurchaseOrderCTP.setPoStatus(rs.getBoolean("po_status"));
        return PurchaseOrderCTP;
    }
}
