/*
 * 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.core.dao.governance.proposal.reimbursement;

import bisq.core.dao.governance.ConsensusCritical;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.governance.proposal.compensation.CompensationConsensus;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.ReimbursementProposal;

import org.bitcoinj.core.Coin;

import javax.inject.Inject;

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.Validate.notEmpty;

/**
 * Changes here can potentially break consensus!
 */
@Slf4j
public class ReimbursementValidator extends ProposalValidator implements ConsensusCritical {

    @Inject
    public ReimbursementValidator(DaoStateService daoStateService, PeriodService periodService) {
        super(daoStateService, periodService);
    }

    @Override
    public void validateDataFields(Proposal proposal) throws ProposalValidationException {
        try {
            super.validateDataFields(proposal);

            ReimbursementProposal reimbursementProposal = (ReimbursementProposal) proposal;
            String bsqAddress = reimbursementProposal.getBsqAddress();
            notEmpty(bsqAddress, "bsqAddress must not be empty");
            checkArgument(bsqAddress.substring(0, 1).equals("B"), "bsqAddress must start with B");
            reimbursementProposal.getAddress(); // throws AddressFormatException if wrong address

            Coin requestedBsq = reimbursementProposal.getRequestedBsq();
            int chainHeight = getBlockHeight(proposal);
            Coin maxCompensationRequestAmount = CompensationConsensus.getMaxCompensationRequestAmount(daoStateService, chainHeight);
            checkArgument(requestedBsq.compareTo(maxCompensationRequestAmount) <= 0,
                    "Requested BSQ must not exceed " + (maxCompensationRequestAmount.value / 100L) + " BSQ");
            Coin minCompensationRequestAmount = CompensationConsensus.getMinCompensationRequestAmount(daoStateService, chainHeight);
            checkArgument(requestedBsq.compareTo(minCompensationRequestAmount) >= 0,
                    "Requested BSQ must not be less than " + (minCompensationRequestAmount.value / 100L) + " BSQ");
        } catch (ProposalValidationException e) {
            throw e;
        } catch (Throwable throwable) {
            throw new ProposalValidationException(throwable);
        }
    }
}

@@ -972,85 +972,8 @@
 or;%0A
-import bisq.core.dao.governance.proposal.compensation.CompensationConsensus;%0A
 impo
@@ -2421,28 +2421,29 @@
 Coin max
-Compensation
+Reimbursement
 RequestA
@@ -2446,36 +2446,37 @@
 estAmount = 
-Compensation
+Reimbursement
 Consensus.ge
@@ -2479,28 +2479,29 @@
 s.getMax
-Compensation
+Reimbursement
 RequestA
@@ -2585,36 +2585,37 @@
 ompareTo(max
-Compensation
+Reimbursement
 RequestAmoun
@@ -2682,28 +2682,29 @@
 %22 + (max
-Compensation
+Reimbursement
 RequestA
@@ -2754,28 +2754,29 @@
 Coin min
-Compensation
+Reimbursement
 RequestA
@@ -2783,28 +2783,29 @@
 mount = 
-Compensation
+Reimbursement
 Consensu
@@ -2812,28 +2812,29 @@
 s.getMin
-Compensation
+Reimbursement
 RequestA
@@ -2918,36 +2918,37 @@
 ompareTo(min
-Compensation
+Reimbursement
 RequestAmoun
@@ -3025,20 +3025,21 @@
 (min
-Compensation
+Reimbursement
 Requ

Fix request amount bounds in ReimbursementValidator