View Javadoc
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.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         return switch (this) {
181             case TAXMAN, GOVERNMENT, MARKET -> true;
182             default -> false;
183         };
184     }
185 
186     /**
187      * Determine whether the PayeeType can parent the deposit type.
188      *
189      * @param pClass the Deposit type
190      * @return <code>true</code> if the payee type can the deposit type, <code>false</code>
191      * otherwise.
192      */
193     public boolean canParentDeposit(final MoneyWiseDepositCategoryClass pClass) {
194         return switch (this) {
195             case GOVERNMENT -> !MoneyWiseDepositCategoryClass.CHECKING.equals(pClass);
196             case INSTITUTION, EMPLOYER -> true;
197             default -> false;
198         };
199     }
200 
201     /**
202      * Determine whether the PayeeType can parent the loan type.
203      *
204      * @param pClass the Loan type
205      * @return <code>true</code> if the payee type can the loan type, <code>false</code> otherwise.
206      */
207     public boolean canParentLoan(final MoneyWiseLoanCategoryClass pClass) {
208         return switch (this) {
209             case TAXMAN, GOVERNMENT, INSTITUTION, EMPLOYER -> !MoneyWiseLoanCategoryClass.PRIVATELOAN.equals(pClass);
210             case INDIVIDUAL -> MoneyWiseLoanCategoryClass.PRIVATELOAN.equals(pClass);
211             default -> false;
212         };
213     }
214 
215     /**
216      * Determine whether the PayeeType can parent the security type.
217      *
218      * @param pClass the Security type
219      * @return <code>true</code> if the payee type can parent the security type, <code>false</code>
220      * otherwise.
221      */
222     public boolean canParentSecurity(final MoneyWiseSecurityClass pClass) {
223         return switch (this) {
224             case MARKET -> pClass.needsMarketParent();
225             case INSTITUTION, EMPLOYER -> !pClass.needsMarketParent();
226             case GOVERNMENT -> pClass.isStatePension();
227             default -> false;
228         };
229     }
230 
231     /**
232      * Determine whether the PayeeType can parent a portfolio.
233      *
234      * @return <code>true</code> if the payee type can parent a portfolio, <code>false</code>
235      * otherwise.
236      */
237     public boolean canParentPortfolio() {
238         return switch (this) {
239             case MARKET, INSTITUTION, EMPLOYER, GOVERNMENT -> true;
240             default -> false;
241         };
242     }
243 
244     /**
245      * Determine whether the PayeeType can contribute to a pension.
246      *
247      * @return <code>true</code> if the payee type can contribute to a pension, <code>false</code>
248      * otherwise.
249      */
250     public boolean canContribPension() {
251         return switch (this) {
252             case INSTITUTION, EMPLOYER, GOVERNMENT, TAXMAN -> true;
253             default -> false;
254         };
255     }
256 
257     /**
258      * Determine whether the PayeeType can provide a taxedIncome.
259      *
260      * @return <code>true</code> if the payee type can parent a portfolio, <code>false</code>
261      * otherwise.
262      */
263     public boolean canProvideTaxedIncome() {
264         return switch (this) {
265             case GOVERNMENT, EMPLOYER, INDIVIDUAL, ANNUITY -> true;
266             default -> false;
267         };
268     }
269 }