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