package com.ecep.contract.cloud.old;

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

import com.ecep.contract.model.CompanyVendorFile;

public class CompanyVendorFileUtils {
    public static boolean applyVendorFileByMap(CompanyVendorFile vendorFile, 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(vendorFile.getFilePath(), filePath)) {
                vendorFile.setFilePath(filePath);
                modified = true;
            }
        }
        if (editFilePath != null) {
            // edit file path
            if (!Objects.equals(vendorFile.getEditFilePath(), editFilePath)) {
                vendorFile.setEditFilePath(editFilePath);
                modified = true;
            }
        }
        if (signDate != null) {
            // date
            LocalDate localDate = signDate.toLocalDate();
            if (!Objects.equals(vendorFile.getSignDate(), localDate)) {
                vendorFile.setSignDate(localDate);
                modified = true;
            }
        }
        if (valid != null) {
            // valid
            if (!Objects.equals(vendorFile.isValid(), valid)) {
                vendorFile.setValid(valid);
                modified = true;
            }
        }
        return modified;
    }

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