001/*
002 * Copyright 2010-2014 Ning, Inc.
003 * Copyright 2014-2015 The Billing Project, LLC
004 *
005 * The Billing Project licenses this file to you under the Apache License, version 2.0
006 * (the "License"); you may not use this file except in compliance with the
007 * License.  You may obtain a copy of the License at:
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.ning.billing.recurly.model;
019
020import com.google.common.base.Objects;
021
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlRootElement;
024import javax.xml.bind.annotation.XmlTransient;
025
026import com.google.common.primitives.Booleans;
027import org.joda.time.DateTime;
028
029@XmlRootElement(name = "account_balance")
030public class AccountBalance extends RecurlyObject {
031
032    @XmlTransient
033    public static final String ACCOUNT_BALANCE_RESOURCE = "/balance";
034
035    @XmlElement(name = "past_due")
036    private Boolean pastDue;
037
038    @XmlElement(name = "balance_in_cents")
039    private RecurlyUnitCurrency balanceInCents;
040
041    public Boolean getPastDue() {
042        return pastDue;
043    }
044
045    public void setPastDue(final Object pastDue) { this.pastDue = booleanOrNull(pastDue); }
046
047    public RecurlyUnitCurrency getBalanceInCents() {
048        return balanceInCents;
049    }
050
051    public void setBalanceInCents(final RecurlyUnitCurrency balanceInCents) { this.balanceInCents = balanceInCents; }
052
053    @Override
054    public String toString() {
055        final StringBuilder sb = new StringBuilder("AccountBalance{");
056        sb.append(", pastDue=").append(pastDue);
057        sb.append(", balanceInCents=").append(balanceInCents);
058        sb.append('}');
059        return sb.toString();
060    }
061
062    @Override
063    public boolean equals(final Object o) {
064        if (this == o) return true;
065        if (o == null || getClass() != o.getClass()) return false;
066
067        final AccountBalance accountBalance = (AccountBalance) o;
068
069        if (pastDue != null ? !pastDue.equals(accountBalance.pastDue) : accountBalance.pastDue != null) {
070            return false;
071        }
072        if (balanceInCents != null ? !balanceInCents.equals(accountBalance.balanceInCents) : accountBalance.balanceInCents != null) {
073            return false;
074        }
075
076        return true;
077    }
078
079    @Override
080    public int hashCode() {
081        return Objects.hashCode(
082                pastDue,
083                balanceInCents
084        );
085    }
086
087
088}