package com.utopiaindustries.dao.uind;

import com.utopiaindustries.model.uind.Item;
import org.springframework.jdbc.core.RowMapper;

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


public class ItemRowMapper implements RowMapper<Item> {
    public Item mapRow( ResultSet rs, int rowNum ) throws SQLException {

        Item item = new Item();
        item.setId(rs.getLong("id"));
        item.setTitle(rs.getString("title"));
        item.setShortTitle(rs.getString("short_title"));
        item.setDescription(rs.getString("description"));
        item.setSpec1(rs.getString("spec1"));
        item.setSpec2(rs.getString("spec2"));
        item.setSpec3(rs.getString("spec3"));
        item.setSpec4(rs.getString("spec4"));
        item.setSpec5(rs.getString("spec5"));
        item.setBrand(rs.getString("brand"));
        item.setYear(rs.getString("year"));
        item.setModel(rs.getString("model"));
        item.setUnitId(rs.getLong("unit_id"));
        item.setCompanyId(rs.getLong("company_id"));
        item.setFunctionId(rs.getLong("function_id"));
        item.setDepartmentId(rs.getLong("department_id"));
        Long sectionId = rs.getLong("section_id");
        if (rs.wasNull()) {
            sectionId = null;
        }
        item.setSectionId(sectionId);
        item.setTypeId(rs.getLong("type_id"));
        item.setCategoryId(rs.getLong("category_id"));
        item.setSubcategoryOneId(rs.getLong("subcategory_one_id"));
        item.setSubcategoryTwoId(rs.getLong("subcategory_two_id"));
        item.setCode(rs.getString("code"));
        item.setItemRequestId(rs.getLong("item_request_id"));
        item.setMinimumLevel(rs.getLong("minimum_level"));
        item.setDeadLevel(rs.getLong("dead_level"));
        item.setStorageLocationSiteId(rs.getLong("storage_location_site_id"));
        item.setStorageLocationUnitId(rs.getLong("storage_location_unit_id"));
        item.setStorageLocationFloorId(rs.getLong("storage_location_floor_id"));
        item.setStorageLocationStoreId(rs.getLong("storage_location_store_id"));
        Long locationShelfId = rs.getLong("storage_location_shelf_id");
        if (rs.wasNull()) {
            locationShelfId = null;
        }
        item.setStorageLocationShelfId(locationShelfId);
        if (rs.getDate("date_added") != null) {
            item.setDateAdded(rs.getDate("date_added").toLocalDate());
        }
        item.setRequestedByUser(rs.getString("requested_by_user"));
        item.setAddedByUser(rs.getString("added_by_user"));
        item.setIsActive(rs.getBoolean("is_active"));
        item.setHsCode(rs.getString("hs_code"));
        item.setImageUrl(rs.getString("image_url"));
        item.setApprovalStatus(rs.getString("approval_status"));
        item.setApprovedBy(rs.getString("approved_by"));
        if (rs.getTimestamp("approved_date") != null) {
            item.setApprovedDate(rs.getTimestamp("approved_date").toLocalDateTime());
        }
        item.setRemarks(rs.getString("remarks"));
        if (rs.getTimestamp("request_date_time") != null) {
            item.setRequestDateTime(rs.getTimestamp("request_date_time").toLocalDateTime());
        }
        item.setMaterialType(rs.getString("material_type"));
        item.setMeasurement(rs.getString("measurement"));
        item.setOrigin(rs.getString("origin"));
        item.setIsSkuSystemGenerated(rs.getBoolean("is_sku_system_generated"));
        item.setIsUpdated(rs.getBoolean("is_updated"));
        item.setSku(rs.getString("sku"));
        if (rs.getTimestamp("last_audit_date") != null) {
            item.setLastAuditDate(rs.getTimestamp("last_audit_date").toLocalDateTime());
        }
        item.setLastAuditUpdateBy(rs.getString("last_audit_updated_by"));
        return item;
    }
}
