1 /*
2 * MoneyWise: Finance Application
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.moneywise.data.statics;
18
19 import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
20 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
21 import io.github.tonywasher.joceanus.oceanus.resource.OceanusBundleId;
22
23 /**
24 * Enumeration of DepositCategory Type Classes.
25 */
26 public enum MoneyWiseDepositCategoryClass
27 implements MoneyWiseCategoryInterface {
28 /**
29 * Checking Deposit.
30 * <p>
31 * These are standard checking deposit accounts that hold money on behalf of the client. Each
32 * such account must be owned by a {@link MoneyWisePayeeClass#INSTITUTION} payee.
33 */
34 CHECKING(1, 1),
35
36 /**
37 * Savings Deposit.
38 * <p>
39 * These are standard savings accounts that hold money on behalf of the client. There is no
40 * distinction as to whether they are easy access or restricted access. Each such account must
41 * be owned by a {@link MoneyWisePayeeClass#INSTITUTION} payee.
42 */
43 SAVINGS(2, 2),
44
45 /**
46 * TaxFreeSavings.
47 * <p>
48 * This a bond account which is a specialised form of an {@link #SAVINGS} account. It has an
49 * associated maturity date for the account.
50 */
51 TAXFREESAVINGS(3, 3),
52
53 /**
54 * Peer2Peer Deposit.
55 * <p>
56 * This a peer2peer account which is a specialised form of an {@link #SAVINGS} account.
57 * LoyaltyBonuses are allowed, and the tax situation varies.
58 */
59 PEER2PEER(4, 4),
60
61 /**
62 * Bond Deposit.
63 * <p>
64 * This a bond account which is a specialised form of an {@link #SAVINGS} account. It has an
65 * associated maturity date for the account.
66 */
67 BOND(5, 5),
68
69 /**
70 * Bond Deposit.
71 * <p>
72 * This a bond account which is a specialised form of an {@link #SAVINGS} account. It has an
73 * associated maturity date for the account.
74 */
75 TAXFREEBOND(6, 6),
76
77 /**
78 * Parent Category.
79 * <p>
80 * This is used as a sub-total bucket and is used purely for reporting purposes.
81 */
82 PARENT(7, 0);
83
84 /**
85 * The String name.
86 */
87 private String theName;
88
89 /**
90 * Class Id.
91 */
92 private final int theId;
93
94 /**
95 * Class Order.
96 */
97 private final int theOrder;
98
99 /**
100 * Constructor.
101 *
102 * @param uId the Id
103 * @param uOrder the default order.
104 */
105 MoneyWiseDepositCategoryClass(final int uId,
106 final int uOrder) {
107 theId = uId;
108 theOrder = uOrder;
109 }
110
111 @Override
112 public int getClassId() {
113 return theId;
114 }
115
116 @Override
117 public int getOrder() {
118 return theOrder;
119 }
120
121 @Override
122 public String toString() {
123 /* If we have not yet loaded the name */
124 if (theName == null) {
125 /* Load the name */
126 theName = bundleIdForCategoryClass(this).getValue();
127 }
128
129 /* return the name */
130 return theName;
131 }
132
133 /**
134 * get value from id.
135 *
136 * @param id the id value
137 * @return the corresponding enum object
138 * @throws OceanusException on error
139 */
140 public static MoneyWiseDepositCategoryClass fromId(final int id) throws OceanusException {
141 for (MoneyWiseDepositCategoryClass myClass : values()) {
142 if (myClass.getClassId() == id) {
143 return myClass;
144 }
145 }
146 throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.DEPOSITTYPE.toString() + ":" + id);
147 }
148
149 /**
150 * Determine whether the DepositCategoryType is a child, and needs a parent.
151 *
152 * @return <code>true</code> if the deposit category type is a child, <code>false</code>
153 * otherwise.
154 */
155 public boolean isChild() {
156 return switch (this) {
157 case CHECKING, SAVINGS, TAXFREESAVINGS, PEER2PEER, BOND, TAXFREEBOND -> true;
158 default -> false;
159 };
160 }
161
162 /**
163 * Determine whether the DepositCategoryType is be tax free.
164 *
165 * @return <code>true</code> if the deposit category type is tax free, <code>false</code>
166 * otherwise.
167 */
168 public boolean isTaxFree() {
169 return switch (this) {
170 case TAXFREESAVINGS, TAXFREEBOND -> true;
171 default -> false;
172 };
173 }
174
175 /**
176 * Determine whether the DepositCategoryType has a maturity date.
177 *
178 * @return <code>true</code> if the deposit category type has maturity, <code>false</code>
179 * otherwise.
180 */
181 public boolean hasMaturity() {
182 return switch (this) {
183 case BOND, TAXFREEBOND -> true;
184 default -> false;
185 };
186 }
187
188 /**
189 * Determine whether the DepositCategoryType is gross.
190 *
191 * @return <code>true</code> if the deposit category type is gross, <code>false</code>
192 * otherwise.
193 */
194 public boolean isGross() {
195 return this == PEER2PEER;
196 }
197
198 /**
199 * Determine whether the DepositCategoryType can provide cashBack.
200 *
201 * @return <code>true</code> if the deposit category type can provide cashBack
202 * <code>false</code> otherwise.
203 */
204 public boolean canCashBack() {
205 return switch (this) {
206 case CHECKING, PEER2PEER -> true;
207 default -> false;
208 };
209 }
210
211 /**
212 * Determine whether the DepositCategoryType can provide loyaltyBonus.
213 *
214 * @return <code>true</code> if the deposit category type can provide loyaltyBonus
215 * <code>false</code> otherwise.
216 */
217 public boolean canLoyaltyBonus() {
218 return this == PEER2PEER;
219 }
220
221 /**
222 * Determine whether the DepositCategoryType is a parent category.
223 *
224 * @return <code>true</code> if the deposit category type is a parent category,
225 * <code>false</code> otherwise.
226 */
227 public boolean isParentCategory() {
228 return this == PARENT;
229 }
230
231 @Override
232 public boolean isTotals() {
233 return false;
234 }
235
236 /**
237 * Obtain the resource bundleId for the category class.
238 *
239 * @param pClass the category class
240 * @return the resource bundleId
241 */
242 private static OceanusBundleId bundleIdForCategoryClass(final MoneyWiseDepositCategoryClass pClass) {
243 /* Create the map and return it */
244 return switch (pClass) {
245 case CHECKING -> MoneyWiseStaticResource.DEPOSITTYPE_CHECKING;
246 case SAVINGS -> MoneyWiseStaticResource.DEPOSITTYPE_SAVINGS;
247 case TAXFREESAVINGS -> MoneyWiseStaticResource.DEPOSITTYPE_TAXFREESAVINGS;
248 case PEER2PEER -> MoneyWiseStaticResource.DEPOSITTYPE_PEER2PEER;
249 case BOND -> MoneyWiseStaticResource.DEPOSITTYPE_BOND;
250 case TAXFREEBOND -> MoneyWiseStaticResource.DEPOSITTYPE_TAXFREEBOND;
251 case PARENT -> MoneyWiseStaticResource.CATEGORYTYPE_PARENT;
252 default -> throw new IllegalArgumentException();
253 };
254 }
255 }