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;
023
024/**
025 * Subscription object for update calls.
026 * <p>
027 * The timeframe parameter is specific to the update.
028 */
029public class SubscriptionUpdate extends AbstractSubscription {
030
031    public static enum Timeframe {
032        now,
033        renewal,
034        bill_date,
035        term_end
036    }
037
038    @XmlElement
039    private Timeframe timeframe;
040
041    @XmlElement(name = "coupon_code")
042    private String couponCode;
043
044    @XmlElement(name = "collection_method")
045    private String collectionMethod;
046
047    @XmlElement(name = "shipping_address")
048    private ShippingAddress shippingAddress;
049
050    @XmlElement(name = "shipping_address_id")
051    private Long shippingAddressId;
052
053    @XmlElement(name = "net_terms")
054    private Integer netTerms;
055
056    @XmlElement(name = "po_number")
057    private String poNumber;
058
059    @XmlElement(name = "revenue_schedule_type")
060    private RevenueScheduleType revenueScheduleType;
061
062    @XmlElement(name = "remaining_billing_cycles")
063    private Integer remainingBillingCycles;
064
065    @XmlElement(name = "imported_trial")
066    private Boolean importedTrial;
067
068    @XmlElement(name = "renewal_billing_cycles")
069    private Integer renewalBillingCycles;
070
071    @XmlElement(name = "auto_renew")
072    private Boolean autoRenew;
073
074    public Timeframe getTimeframe() {
075        return timeframe;
076    }
077
078    public void setTimeframe(final Timeframe timeframe) {
079        this.timeframe = timeframe;
080    }
081
082    public String getCollectionMethod() {
083        return collectionMethod;
084    }
085
086    public void setCollectionMethod(final Object collectionMethod) {
087        this.collectionMethod = stringOrNull(collectionMethod);
088    }
089
090    public String getCouponCode() {
091        return couponCode;
092    }
093
094    public void setCouponCode(final Object couponCode) {
095        this.couponCode = stringOrNull(couponCode);
096    }
097
098    public void setShippingAddress(final ShippingAddress shippingAddress) {
099        this.shippingAddress = shippingAddress;
100    }
101
102    public ShippingAddress getShippingAddress() {
103        return shippingAddress;
104    }
105
106    public void setShippingAddressId(final Object shippingAddressId) {
107        this.shippingAddressId = longOrNull(shippingAddressId);
108    }
109
110    public Integer getNetTerms() {
111        return netTerms;
112    }
113
114    public void setNetTerms(final Object netTerms) {
115        this.netTerms = integerOrNull(netTerms);
116    }
117
118    public String getPoNumber() {
119        return poNumber;
120    }
121
122    public void setPoNumber(Object poNumber) {
123        this.poNumber = stringOrNull(poNumber);
124    }
125
126    public RevenueScheduleType getRevenueScheduleType() {
127        return revenueScheduleType;
128    }
129
130    public void setRevenueScheduleType(final Object revenueScheduleType) {
131        this.revenueScheduleType = enumOrNull(RevenueScheduleType.class, revenueScheduleType, true);
132    }
133
134    public Integer getRemainingBillingCycles() {
135        return remainingBillingCycles;
136    }
137
138    public void setRemainingBillingCycles(final Object remainingBillingCycles) {
139        this.remainingBillingCycles = integerOrNull(remainingBillingCycles);
140    }
141
142    public Boolean getImportedTrial() {
143        return this.importedTrial;
144    }
145
146    public void setImportedTrial(final Object importedTrial) {
147        this.importedTrial = booleanOrNull(importedTrial);
148    }
149
150    public Integer getRenewalBillingCycles() {
151        return renewalBillingCycles;
152    }
153
154    public void setRenewalBillingCycles(final Object renewalBillingCycles) {
155        this.renewalBillingCycles = integerOrNull(renewalBillingCycles);
156    }
157
158    public Boolean getAutoRenew() {
159        return this.autoRenew;
160    }
161
162    public void setAutoRenew(final Object autoRenew) {
163        this.autoRenew = booleanOrNull(autoRenew);
164    }
165
166    @Override
167    public boolean equals(final Object o) {
168        if (this == o) return true;
169        if (o == null || getClass() != o.getClass()) return false;
170
171        final SubscriptionUpdate that = (SubscriptionUpdate) o;
172
173        if (collectionMethod != null ? !collectionMethod.equals(that.collectionMethod) : that.collectionMethod != null) {
174            return false;
175        }
176        if (timeframe != that.timeframe) {
177            return false;
178        }
179        if (couponCode != null ? !couponCode.equals(that.couponCode) : that.couponCode != null) {
180            return false;
181        }
182        if (shippingAddress != null ? !shippingAddress.equals(that.shippingAddress) : that.shippingAddress != null) {
183            return false;
184        }
185        if (shippingAddressId != null ? !shippingAddressId.equals(that.shippingAddressId) : that.shippingAddressId != null) {
186            return false;
187        }
188        if (customFields != null ? !customFields.equals(that.customFields) : that.customFields != null) {
189            return false;
190        }
191        if (netTerms != null ? !netTerms.equals(that.netTerms) : that.netTerms != null) {
192            return false;
193        }
194        if (poNumber != null ? !poNumber.equals(that.poNumber) : that.poNumber != null) {
195            return false;
196        }
197        if (revenueScheduleType != null ? !revenueScheduleType.equals(that.revenueScheduleType) : that.revenueScheduleType != null) {
198            return false;
199        }
200        if (remainingBillingCycles != null ? !remainingBillingCycles.equals(that.remainingBillingCycles) : that.remainingBillingCycles != null) {
201            return false;
202        }
203        if (importedTrial != null ? !importedTrial.equals(that.importedTrial) : that.importedTrial != null) {
204            return false;
205        }
206        if (renewalBillingCycles != null ? !renewalBillingCycles.equals(that.renewalBillingCycles) : that.renewalBillingCycles != null) {
207            return false;
208        }
209        if (autoRenew != null ? !autoRenew.equals(that.autoRenew) : that.autoRenew != null) {
210            return false;
211        }
212
213        return true;
214    }
215
216    @Override
217    public int hashCode() {
218        return Objects.hashCode(
219                timeframe,
220                couponCode,
221                collectionMethod,
222                shippingAddress,
223                shippingAddressId,
224                customFields,
225                netTerms,
226                poNumber,
227                revenueScheduleType,
228                remainingBillingCycles,
229                importedTrial,
230                renewalBillingCycles,
231                autoRenew
232        );
233    }
234}