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.oceanus.base.OceanusException;
20 import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
21 import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataClass;
22
23 /**
24 * Enumeration of Payee Type Classes.
25 */
26 public enum MoneyWisePayeeClass
27 implements PrometheusStaticDataClass {
28 /**
29 * Generic Payee Account.
30 * <p>
31 * This is a simple payee that represents an entity that monies are paid to.
32 */
33 PAYEE(1, 0),
34
35 /**
36 * Employer Account.
37 * <p>
38 * This is an employer account which is a specialised form of an {@link #INSTITUTION} payee. It
39 * has the ability to pay dividends.
40 */
41 EMPLOYER(2, 1),
42
43 /**
44 * Institution Payee.
45 * <p>
46 * This is an institution (e.g. a bank) that holds another account of behalf of the client. It
47 * is a specialised form of payee.
48 */
49 INSTITUTION(3, 2),
50
51 /**
52 * LoanHolder Account.
53 * <p>
54 * This is an individual who can own a PrivateLoan account, and who can be inherited from. It is
55 * a specialised form of a payee.
56 */
57 INDIVIDUAL(4, 3),
58
59 /**
60 * Annuity.
61 * <p>
62 * This is an annuity that pays a TaxedIncome with TaxCredit and no NatInsurance.
63 */
64 ANNUITY(5, 4),
65
66 /**
67 * Inland Revenue.
68 * <p>
69 * This is a singular payee representing the tax authority. All TaxCredits etc. are deemed to
70 * have been paid to the single account of this type.
71 */
72 TAXMAN(6, 5),
73
74 /**
75 * Government.
76 * <p>
77 * This is a singular payee representing the government. All Local Taxes should be paid to the
78 * single account of this type.
79 */
80 GOVERNMENT(7, 6),
81
82 /**
83 * Market pseudo account.
84 * <p>
85 * This is a singular payee representing the market. All increases/decreases in value of an
86 * asset that are due to fluctuations in unit prices are viewed as income/expense from the
87 * single account of this type.
88 */
89 MARKET(8, 7);
90
91 /**
92 * The String name.
93 */
94 private String theName;
95
96 /**
97 * Class Id.
98 */
99 private final int theId;
100
101 /**
102 * Class Order.
103 */
104 private final int theOrder;
105
106 /**
107 * Constructor.
108 *
109 * @param uId the Id
110 * @param uOrder the default order.
111 */
112 MoneyWisePayeeClass(final int uId,
113 final int uOrder) {
114 theId = uId;
115 theOrder = uOrder;
116 }
117
118 @Override
119 public int getClassId() {
120 return theId;
121 }
122
123 @Override
124 public int getOrder() {
125 return theOrder;
126 }
127
128 @Override
129 public String toString() {
130 /* If we have not yet loaded the name */
131 if (theName == null) {
132 /* Load the name */
133 theName = MoneyWiseStaticResource.getKeyForPayeeType(this).getValue();
134 }
135
136 /* return the name */
137 return theName;
138 }
139
140 /**
141 * get value from id.
142 *
143 * @param id the id value
144 * @return the corresponding enum object
145 * @throws OceanusException on error
146 */
147 public static MoneyWisePayeeClass fromId(final int id) throws OceanusException {
148 for (MoneyWisePayeeClass myClass : values()) {
149 if (myClass.getClassId() == id) {
150 return myClass;
151 }
152 }
153 throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.PAYEETYPE.toString() + ":" + id);
154 }
155
156 /**
157 * Determine whether the payeeType is hidden type.
158 *
159 * @return <code>true</code> if the payee is hidden, <code>false</code> otherwise.
160 */
161 public boolean isHiddenType() {
162 return this == MARKET;
163 }
164
165 /**
166 * Determine whether the payeeType is hidden type.
167 *
168 * @return <code>true</code> if the payee is hidden, <code>false</code> otherwise.
169 */
170 public boolean isAnnuity() {
171 return this == ANNUITY;
172 }
173
174 /**
175 * Determine whether the payee type is singular.
176 *
177 * @return <code>true</code> if the payee type is singular, <code>false</code> otherwise.
178 */
179 public boolean isSingular() {
180 switch (this) {
181 case TAXMAN:
182 case GOVERNMENT:
183 case MARKET:
184 return true;
185 default:
186 return false;
187 }
188 }
189
190 /**
191 * Determine whether the PayeeType can parent the deposit type.
192 *
193 * @param pClass the Deposit type
194 * @return <code>true</code> if the payee type can the deposit type, <code>false</code>
195 * otherwise.
196 */
197 public boolean canParentDeposit(final MoneyWiseDepositCategoryClass pClass) {
198 switch (this) {
199 case GOVERNMENT:
200 return !MoneyWiseDepositCategoryClass.CHECKING.equals(pClass);
201 case INSTITUTION:
202 case EMPLOYER:
203 return true;
204 case PAYEE:
205 case INDIVIDUAL:
206 case MARKET:
207 case TAXMAN:
208 case ANNUITY:
209 default:
210 return false;
211 }
212 }
213
214 /**
215 * Determine whether the PayeeType can parent the loan type.
216 *
217 * @param pClass the Loan type
218 * @return <code>true</code> if the payee type can the loan type, <code>false</code> otherwise.
219 */
220 public boolean canParentLoan(final MoneyWiseLoanCategoryClass pClass) {
221 switch (this) {
222 case TAXMAN:
223 case GOVERNMENT:
224 case INSTITUTION:
225 case EMPLOYER:
226 return !MoneyWiseLoanCategoryClass.PRIVATELOAN.equals(pClass);
227 case INDIVIDUAL:
228 return MoneyWiseLoanCategoryClass.PRIVATELOAN.equals(pClass);
229 case MARKET:
230 case PAYEE:
231 case ANNUITY:
232 default:
233 return false;
234 }
235 }
236
237 /**
238 * Determine whether the PayeeType can parent the security type.
239 *
240 * @param pClass the Security type
241 * @return <code>true</code> if the payee type can parent the security type, <code>false</code>
242 * otherwise.
243 */
244 public boolean canParentSecurity(final MoneyWiseSecurityClass pClass) {
245 switch (this) {
246 case MARKET:
247 return pClass.needsMarketParent();
248 case INSTITUTION:
249 case EMPLOYER:
250 return !pClass.needsMarketParent();
251 case GOVERNMENT:
252 return pClass.isStatePension();
253 case TAXMAN:
254 case INDIVIDUAL:
255 case PAYEE:
256 case ANNUITY:
257 default:
258 return false;
259 }
260 }
261
262 /**
263 * Determine whether the PayeeType can parent a portfolio.
264 *
265 * @return <code>true</code> if the payee type can parent a portfolio, <code>false</code>
266 * otherwise.
267 */
268 public boolean canParentPortfolio() {
269 switch (this) {
270 case MARKET:
271 case INSTITUTION:
272 case EMPLOYER:
273 case GOVERNMENT:
274 return true;
275 case TAXMAN:
276 case INDIVIDUAL:
277 case PAYEE:
278 case ANNUITY:
279 default:
280 return false;
281 }
282 }
283
284 /**
285 * Determine whether the PayeeType can contribute to a pension.
286 *
287 * @return <code>true</code> if the payee type can contribute to a pension, <code>false</code>
288 * otherwise.
289 */
290 public boolean canContribPension() {
291 switch (this) {
292 case INSTITUTION:
293 case EMPLOYER:
294 case GOVERNMENT:
295 case TAXMAN:
296 return true;
297 case MARKET:
298 case INDIVIDUAL:
299 case PAYEE:
300 case ANNUITY:
301 default:
302 return false;
303 }
304 }
305
306 /**
307 * Determine whether the PayeeType can provide a taxedIncome.
308 *
309 * @return <code>true</code> if the payee type can parent a portfolio, <code>false</code>
310 * otherwise.
311 */
312 public boolean canProvideTaxedIncome() {
313 switch (this) {
314 case GOVERNMENT:
315 case EMPLOYER:
316 case INDIVIDUAL:
317 case ANNUITY:
318 return true;
319 case MARKET:
320 case TAXMAN:
321 case PAYEE:
322 default:
323 return false;
324 }
325 }
326 }