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