package hr.com.port.ips.eracun.validation;

import org.w3c.dom.Document;

public final class Bt {
    private Bt() {}

    public static String get(Document doc, String btKey) throws Exception {
        String xp = BtPaths.xpath(btKey);
        if (xp == null) return "";
        XmlEval x = new XmlEval();
        String v = x.str(doc, xp);
        return v == null ? "" : v;
    }

    public static boolean has(Document doc, String btKey) throws Exception {
        String v = get(doc, btKey);
        return v != null && v.trim().length() > 0;
    }

    public static String customerName(Document doc) throws Exception {
        XmlEval x = new XmlEval();
        String p1 = x.str(doc, "/*[local-name()='Invoice']/*[local-name()='AccountingCustomerParty']/*[local-name()='Party']/*[local-name()='PartyName']/*[local-name()='Name']/text()");
        if (p1 != null && p1.trim().length() > 0) return p1;
        String p2 = x.str(doc, "/*[local-name()='Invoice']/*[local-name()='AccountingCustomerParty']/*[local-name()='Party']/*[local-name()='PartyLegalEntity']/*[local-name()='RegistrationName']/text()");
        return p2 == null ? "" : p2;
    }
}
