001/* This file is part of Vault.
002
003    Vault is free software: you can redistribute it and/or modify
004    it under the terms of the GNU Lesser General Public License as published by
005    the Free Software Foundation, either version 3 of the License, or
006    (at your option) any later version.
007
008    Vault is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU Lesser General Public License for more details.
012
013    You should have received a copy of the GNU Lesser General Public License
014    along with Vault.  If not, see <http://www.gnu.org/licenses/>.
015 */
016package net.milkbowl.vault.economy;
017
018/**
019 * Indicates a typical Return for an Economy method.  
020 * It includes a {@link ResponseType} indicating whether the plugin currently being used for Economy actually allows
021 * the method, or if the operation was a success or failure.
022 *
023 */
024public class EconomyResponse {
025
026    /**
027     * Enum for types of Responses indicating the status of a method call.
028     */
029    public static enum ResponseType {
030        SUCCESS(1),
031        FAILURE(2),
032        NOT_IMPLEMENTED(3);
033
034        private int id;
035
036        ResponseType(int id) {
037            this.id = id;
038        }
039
040        int getId() {
041            return id;
042        }
043    }
044
045    /**
046     * Amount modified by calling method
047     */
048    public final double amount;
049    /**
050     * New balance of account
051     */
052    public final double balance;
053    /**
054     * Success or failure of call. Using Enum of ResponseType to determine valid
055     * outcomes
056     */
057    public final ResponseType type;
058    /**
059     * Error message if the variable 'type' is ResponseType.FAILURE
060     */
061    public final String errorMessage;
062
063    /**
064     * Constructor for EconomyResponse
065     * @param amount Amount modified during operation
066     * @param balance New balance of account
067     * @param type Success or failure type of the operation
068     * @param errorMessage Error message if necessary (commonly null)
069     */
070    public EconomyResponse(double amount, double balance, ResponseType type, String errorMessage) {
071        this.amount = amount;
072        this.balance = balance;
073        this.type = type;
074        this.errorMessage = errorMessage;
075    }
076
077    /**
078     * Checks if an operation was successful
079     * @return Value
080     */
081    public boolean transactionSuccess() {
082        switch (type) {
083        case SUCCESS:
084            return true;
085        default:
086            return false;
087        }
088    }
089}