complex-barcode/swiss-qr-bill.js

const _MwWrapper = require("../_mwbridge/_mw-wrapper.js");
const Address = require("./address");
const {J_ArrayList} = require("../_mwbridge/_mw-bridge");
const AlternativeScheme = require("./alternative-scheme");

/**
 * SwissQR bill data
 */
class SwissQRBill extends _MwWrapper
{
    creditor;
    debtor;

    _initializeWrapperMembers() {
        this.creditor = Address.fromMwObject(this.getJavaClass().getCreditorSync());
        this.debtor = Address.fromMwObject(this.getJavaClass().getDebtorSync());
    }

    constructor(mwObject) {
        super(mwObject);
        this._initializeWrapperMembers();
    }

    static convertAlternativeSchemes(javaAlternativeSchemes) {
        let alternativeSchemes = [];
        for (let i = 0; i < javaAlternativeSchemes.sizeSync(); i++) {
            alternativeSchemes[i] = AlternativeScheme._fromMwObject(javaAlternativeSchemes.getSync(i));
        }
        return alternativeSchemes;
    }

    /**
     * Gets the version of the SwissQR bill standard.
     * @return The SwissQR bill standard version.
     */
    getVersion() {
        return this.getJavaClass().getVersionSync();
    }

    /**
     * Sets the version of the SwissQR bill standard.<br>
     * @param value The SwissQR bill standard version.
     */
    setVersion(value) {
        this.getJavaClass().setVersionSync(value);
    }

    /**
     * Gets the payment amount.<br>
     * <br>
     * Valid values are between 0.01 and 999,999,999.99.
     *
     * @return The payment amount.
     */
    getAmount() {
        return this.getJavaClass().getAmountSync();
    }

    /**
     * Sets the payment amount.<br>
     * Valid values are between 0.01 and 999,999,999.99.
     *
     * @param value The payment amount.
     */
    setAmount(value) {
        this.getJavaClass().setAmountSync(value);
    }

    /**
     * Gets the payment currency.<br>
     *
     * Valid values are "CHF" and "EUR".
     *
     * @return The payment currency.
     */
    getCurrency() {
        return this.getJavaClass().getCurrencySync();
    }

    /**
     * Sets the payment currency.<br>
     *
     * @param value Valid values are "CHF" and "EUR".
     */
    setCurrency(value) {
        this.getJavaClass().setCurrencySync(value);
    }

    /**
     * Gets the creditor's account number.<br>
     * <br>
     * Account numbers must be valid IBANs of a bank of Switzerland or<br>
     * Liechtenstein. Spaces are allowed in the account number.<br>
     *
     * @return The creditor account number.
     */
    getAccount() {
        return this.getJavaClass().getAccountSync();
    }

    /**
     * Sets the creditor's account number.<br>
     * <br>
     * Account numbers must be valid IBANs of a bank of Switzerland<br> or<br>
     * Liechtenstein. Spaces are allowed in the account number.
     *
     * @param value: The creditor account number.
     */
    setAccount(value) {
        this.getJavaClass().setAccountSync(value);
    }

    /**
     * Gets the creditor address.
     * @return The creditor address.
     */
    getCreditor() {
        return this.creditor;
    }

    /**
     * Sets the creditor address.
     * @param value: The creditor address.
     */
    setCreditor(value) {
        this.creditor = value;
        this.getJavaClass().setCreditorSync(value.getJavaClass());
    }

    /**
     * Gets the creditor payment reference.<br>
     * <br>
     * The reference is mandatory for SwissQR IBANs, i.e.IBANs in the range<br>
     * CHxx30000xxxxxx through CHxx31999xxxxx.<br>
     * <br>
     * If specified, the reference must be either a valid SwissQR reference<br>
     * (corresponding to ISR reference form) or a valid creditor reference<br>
     * according to ISO 11649 ("RFxxxx"). Both may contain spaces for formatting.<br>
     *
     * @return The creditor payment reference.
     */
    getReference() {
        return this.getJavaClass().getReferenceSync();
    }

    /**
     * Sets the creditor payment reference.<br>
     * <br>
     * The reference is mandatory for SwissQR IBANs, i.e.IBANs in the range<br>
     * CHxx30000xxxxxx through CHxx31999xxxxx.<br>
     * <br>
     * If specified, the reference must be either a valid SwissQR reference<br>
     * (corresponding to ISR reference form) or a valid creditor reference<br>
     * according to ISO 11649 ("RFxxxx"). Both may contain spaces for formatting.
     *
     * @param value The creditor payment reference.
     */
    setReference(value) {
        this.getJavaClass().setReferenceSync(value);
    }

    /**
     * Creates and sets a ISO11649 creditor reference from a raw string by prefixing<br>
     * the String with "RF" and the modulo 97 checksum.<br>
     * <br>
     * Whitespace is removed from the reference<br>
     * <br>
     * @exception ArgumentException rawReference contains invalid characters.
     * @param rawReference The raw reference.
     */
    createAndSetCreditorReference(rawReference) {
        this.getJavaClass().createAndSetCreditorReferenceSync(rawReference);
    }

    /**
     * Gets the debtor address.<br>
     * <br>
     * The debtor is optional. If it is omitted, both setting this field to<br>
     * null or setting an address with all null or empty values is ok.<br>
     * <br>
     * @return The debtor address.
     */
    getDebtor() {
        return this.debtor;
    }

    /**
     * Sets the debtor address.<br>
     * <br>
     * The debtor is optional. If it is omitted, both setting this field to<br>
     * null or setting an address with all null or empty values is ok.
     *
     * @param value: The debtor address.
     */
    setDebtor(value) {
        this.debtor = value;
        this.getJavaClass().setDebtorSync(value.getJavaClass());
    }

    /**
     * Gets the additional unstructured message.
     * @return The unstructured message.
     */
    getUnstructuredMessage() {
        return this.getJavaClass().getUnstructuredMessageSync();
    }

    /**
     * Sets the additional unstructured message.
     * @param value: The unstructured message.
     */
    setUnstructuredMessage(value) {
        this.getJavaClass().setUnstructuredMessageSync(value);
    }

    /**
     * Gets the additional structured bill information.
     * @return The structured bill information.
     */
    getBillInformation() {
        return this.getJavaClass().getBillInformationSync();
    }

    /**
     * Sets the additional structured bill information.
     * @param value: The structured bill information.
     */
    setBillInformation(value) {
        this.getJavaClass().setBillInformationSync(value);
    }

    /**
     * Gets ors sets the alternative payment schemes.<br>
     * <br>
     * A maximum of two schemes with parameters are allowed.
     *
     * @return The alternative payment schemes.
     */
    getAlternativeSchemes() {
        return SwissQRBill.convertAlternativeSchemes(this.getJavaClass().getAlternativeSchemesSync());
    }

    /**
     * Gets or sets the alternative payment schemes. <br>
     * <br>
     * A maximum of two schemes with parameters are allowed.<br>
     *
     * @param value: The alternative payment schemes.
     */
    setAlternativeSchemes(value)
    {
        let javaArray = new J_ArrayList();
        for(let i = 0; i < value.length; i++)
        {
            javaArray.addSync(value[i].getJavaClass());
        }
        this.getJavaClass().setAlternativeSchemesSync(javaArray);
    }

    /**
     * Determines whether the specified object is equal to the current object.
     * @return true if the specified object is equal to the current object; otherwise, false.
     * @param obj The object to compare with the current object.
     */
    equals(obj) {
        return this.getJavaClass().equalsSync(obj.getJavaClass());
    }

    /**
     * Gets the hash code for this instance.
     * @return A hash code for the current object.
     */
    hashCode() {
        return this.getJavaClass().hashCodeSync();
    }
}

module.exports = SwissQRBill