package com.ecep.contract.cloud.old;

import java.time.LocalDate;
import java.util.Map;
import java.util.Objects;

import com.ecep.contract.model.CompanyCustomerFile;

public class CompanyCustomerFileUtils {
    public static boolean applyCustomerFileByMap(CompanyCustomerFile customerFile, Map<String, Object> m) {
        boolean modified = false;

        String filePath = (String) m.get("FILE_PATH");
        String editFilePath = (String) m.get("EDIT_FILE_PATH");
        java.sql.Date signDate = (java.sql.Date) m.get("SIGN_DATE");
        Boolean valid = (Boolean) m.get("VALID");

        if (filePath != null) {
            // file path
            if (!Objects.equals(customerFile.getFilePath(), filePath)) {
                customerFile.setFilePath(filePath);
                modified = true;
            }
        }
        if (editFilePath != null) {
            // edit file path
            if (!Objects.equals(customerFile.getEditFilePath(), editFilePath)) {
                customerFile.setEditFilePath(editFilePath);
                modified = true;
            }
        }
        if (signDate != null) {
            // date
            LocalDate localDate = signDate.toLocalDate();
            if (!Objects.equals(customerFile.getSignDate(), localDate)) {
                customerFile.setSignDate(localDate);
                modified = true;
            }
        }
        if (valid != null) {
            // valid
            if (!Objects.equals(customerFile.isValid(), valid)) {
                customerFile.setValid(valid);
                modified = true;
            }
        }
        return modified;
    }

    public static String getCustomerFileKey(Map<String, Object> m) {
        return m.get("FILE_PATH").toString();
    }
}
