/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.desktop.util.validation;

import bisq.core.locale.Res;
import bisq.core.payment.PaymentAccount;
import bisq.core.util.BSFormatter;

import javax.inject.Inject;

import static bisq.core.btc.wallet.Restrictions.getMaxBuyerSecurityDepositAsPercent;
import static bisq.core.btc.wallet.Restrictions.getMinBuyerSecurityDepositAsPercent;

public class SecurityDepositValidator extends NumberValidator {

    private final BSFormatter formatter;
    private PaymentAccount paymentAccount;

    @Inject
    public SecurityDepositValidator(BSFormatter formatter) {
        this.formatter = formatter;
    }

    public void setPaymentAccount(PaymentAccount paymentAccount) {
        this.paymentAccount = paymentAccount;
    }

    @Override
    public ValidationResult validate(String input) {
        ValidationResult result = validateIfNotEmpty(input);
        if (result.isValid) {
            input = cleanInput(input);
            result = validateIfNumber(input);
        }

        if (result.isValid) {
            result = validateIfNotZero(input)
                    .and(validateIfNotNegative(input))
                    .and(validateIfNotTooLowPercentageValue(input))
                    .and(validateIfNotTooHighPercentageValue(input));
        }
        return result;
    }


    private ValidationResult validateIfNotTooLowPercentageValue(String input) {
        try {
            double percentage = formatter.parsePercentStringToDouble(input);
            double minPercentage = getMinBuyerSecurityDepositAsPercent(paymentAccount);
            if (percentage < minPercentage)
                return new ValidationResult(false,
                        Res.get("validation.inputTooSmall", formatter.formatToPercentWithSymbol(minPercentage)));
            else
                return new ValidationResult(true);
        } catch (Throwable t) {
            return new ValidationResult(false, Res.get("validation.invalidInput", t.getMessage()));
        }
    }

    private ValidationResult validateIfNotTooHighPercentageValue(String input) {
        try {
            double percentage = formatter.parsePercentStringToDouble(input);
            double maxPercentage = getMaxBuyerSecurityDepositAsPercent(paymentAccount);
            if (percentage > maxPercentage)
                return new ValidationResult(false,
                        Res.get("validation.inputTooLarge", formatter.formatToPercentWithSymbol(maxPercentage)));
            else
                return new ValidationResult(true);
        } catch (Throwable t) {
            return new ValidationResult(false, Res.get("validation.invalidInput", t.getMessage()));
        }
    }
}

@@ -714,16 +714,58 @@
 ation;%0A%0A
+import bisq.core.btc.wallet.Restrictions;%0A
 import b
@@ -785,16 +785,16 @@
 le.Res;%0A
-
 import b
@@ -862,16 +862,16 @@
 atter;%0A%0A
+
 import j
@@ -895,179 +895,8 @@
 t;%0A%0A
-import static bisq.core.btc.wallet.Restrictions.getMaxBuyerSecurityDepositAsPercent;%0Aimport static bisq.core.btc.wallet.Restrictions.getMinBuyerSecurityDepositAsPercent;%0A%0A
 publ
@@ -2043,24 +2043,37 @@
 ercentage = 
+Restrictions.
 getMinBuyerS
@@ -2746,16 +2746,29 @@
 ntage = 
+Restrictions.
 getMaxBu

Remove unnecessary static import