@stevenkellner/team-conduct-api 2.0.18 → 2.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/lib/src/functions/fine/add.d.ts +3 -8
  2. package/lib/src/functions/fine/add.js +1 -2
  3. package/lib/src/functions/fine/delete.d.ts +1 -6
  4. package/lib/src/functions/fine/delete.js +2 -3
  5. package/lib/src/functions/fine/update.d.ts +2 -8
  6. package/lib/src/functions/fine/update.js +1 -3
  7. package/lib/src/functions/fineTemplate/add.d.ts +3 -3
  8. package/lib/src/functions/fineTemplate/update.d.ts +3 -3
  9. package/lib/src/functions/firebaseFunctionsContext.d.ts +34 -1
  10. package/lib/src/functions/firebaseFunctionsContext.js +33 -33
  11. package/lib/src/functions/index.d.ts +10 -8
  12. package/lib/src/functions/index.js +11 -8
  13. package/lib/src/functions/notification/markNotificationAsRead.d.ts +14 -0
  14. package/lib/src/functions/notification/{subscribe.js → markNotificationAsRead.js} +5 -7
  15. package/lib/src/functions/person/kickout.d.ts +6 -6
  16. package/lib/src/functions/person/kickout.js +4 -4
  17. package/lib/src/functions/person/roleEdit.d.ts +5 -5
  18. package/lib/src/functions/person/roleEdit.js +3 -3
  19. package/lib/src/functions/{paypalMe/edit.d.ts → team/delete.d.ts} +5 -7
  20. package/lib/src/functions/{paypalMe/edit.js → team/delete.js} +4 -5
  21. package/lib/src/functions/team/new.d.ts +18 -18
  22. package/lib/src/functions/team/new.js +8 -4
  23. package/lib/src/functions/team/update.d.ts +34 -0
  24. package/lib/src/functions/team/update.js +23 -0
  25. package/lib/src/functions/user/register.d.ts +4 -0
  26. package/lib/src/functions/user/register.js +3 -1
  27. package/lib/src/functions/user/update.d.ts +26 -0
  28. package/lib/src/functions/user/update.js +15 -0
  29. package/lib/src/index.d.ts +1 -1
  30. package/lib/src/index.js +1 -1
  31. package/lib/src/locales/de.d.ts +1 -1
  32. package/lib/src/locales/de.js +6 -2
  33. package/lib/src/locales/en.d.ts +6 -2
  34. package/lib/src/locales/en.js +6 -2
  35. package/lib/src/types/{MoneyAmount.d.ts → Money.d.ts} +23 -23
  36. package/lib/src/types/{MoneyAmount.js → Money.js} +25 -25
  37. package/lib/src/types/fine/Fine.d.ts +275 -0
  38. package/lib/src/types/fine/Fine.js +318 -0
  39. package/lib/src/types/fine/FineTemplate.d.ts +154 -0
  40. package/lib/src/types/fine/FineTemplate.js +170 -0
  41. package/lib/src/types/{PayedState.d.ts → fine/PayedState.d.ts} +1 -1
  42. package/lib/src/types/{PayedState.js → fine/PayedState.js} +1 -1
  43. package/lib/src/types/fine/index.d.ts +3 -0
  44. package/lib/src/{firebase → types/fine}/index.js +3 -6
  45. package/lib/src/types/index.d.ts +7 -18
  46. package/lib/src/types/index.js +7 -18
  47. package/lib/src/types/{Localization.d.ts → localization/Localization.d.ts} +15 -43
  48. package/lib/src/types/localization/Localization.js +54 -0
  49. package/lib/src/types/localization/PluralLocalization.d.ts +23 -0
  50. package/lib/src/types/localization/PluralLocalization.js +35 -0
  51. package/lib/src/types/{Pluralization.d.ts → localization/Pluralization.d.ts} +1 -0
  52. package/lib/src/types/{Pluralization.js → localization/Pluralization.js} +1 -0
  53. package/lib/src/types/localization/ValueLocalization.d.ts +22 -0
  54. package/lib/src/types/localization/ValueLocalization.js +41 -0
  55. package/lib/src/types/localization/index.d.ts +5 -0
  56. package/lib/src/types/localization/index.js +21 -0
  57. package/lib/src/types/notification/InAppNotification.d.ts +152 -0
  58. package/lib/src/types/notification/InAppNotification.js +136 -0
  59. package/lib/src/types/notification/index.d.ts +1 -0
  60. package/lib/src/types/notification/index.js +17 -0
  61. package/lib/src/types/{Person.d.ts → person/Person.d.ts} +3 -3
  62. package/lib/src/types/{Person.js → person/Person.js} +3 -3
  63. package/lib/src/types/{PersonProperties.d.ts → person/PersonProperties.d.ts} +8 -7
  64. package/lib/src/types/{PersonProperties.js → person/PersonProperties.js} +7 -6
  65. package/lib/src/types/{PersonSignInProperties.d.ts → person/PersonSignInProperties.d.ts} +9 -11
  66. package/lib/src/types/{PersonSignInProperties.js → person/PersonSignInProperties.js} +7 -10
  67. package/lib/src/types/person/index.d.ts +3 -0
  68. package/lib/src/types/person/index.js +19 -0
  69. package/lib/src/types/{Invitation.d.ts → team/Invitation.d.ts} +1 -1
  70. package/lib/src/types/{Invitation.js → team/Invitation.js} +1 -1
  71. package/lib/src/types/team/Team.d.ts +144 -0
  72. package/lib/src/types/team/Team.js +141 -0
  73. package/lib/src/types/team/TeamRole.d.ts +30 -0
  74. package/lib/src/types/{UserRole.js → team/TeamRole.js} +16 -15
  75. package/lib/src/types/team/index.d.ts +3 -0
  76. package/lib/src/types/team/index.js +19 -0
  77. package/lib/src/types/{NotificationProperties.d.ts → user/NotificationProperties.d.ts} +8 -3
  78. package/lib/src/types/{NotificationProperties.js → user/NotificationProperties.js} +4 -0
  79. package/lib/src/types/user/User.d.ts +328 -0
  80. package/lib/src/types/user/User.js +355 -0
  81. package/lib/src/types/user/index.d.ts +2 -0
  82. package/lib/src/types/user/index.js +18 -0
  83. package/lib/src/utils/StaticUnionTypeBuilder.d.ts +9 -0
  84. package/lib/src/utils/StaticUnionTypeBuilder.js +23 -0
  85. package/lib/src/utils/index.d.ts +1 -0
  86. package/lib/src/utils/index.js +17 -0
  87. package/lib/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +4 -3
  89. package/src/functions/fine/add.ts +3 -5
  90. package/src/functions/fine/delete.ts +3 -5
  91. package/src/functions/fine/update.ts +2 -5
  92. package/src/functions/firebaseFunctionsContext.ts +40 -40
  93. package/src/functions/index.ts +11 -9
  94. package/src/functions/notification/markNotificationAsRead.ts +19 -0
  95. package/src/functions/person/add.ts +1 -1
  96. package/src/functions/person/kickout.ts +6 -6
  97. package/src/functions/person/roleEdit.ts +5 -5
  98. package/src/functions/{paypalMe/edit.ts → team/delete.ts} +5 -7
  99. package/src/functions/team/new.ts +19 -11
  100. package/src/functions/team/update.ts +40 -0
  101. package/src/functions/user/register.ts +7 -3
  102. package/src/functions/user/update.ts +29 -0
  103. package/src/index.ts +1 -1
  104. package/src/locales/de.ts +7 -3
  105. package/src/locales/en.ts +7 -3
  106. package/src/types/{MoneyAmount.ts → Money.ts} +29 -29
  107. package/src/types/fine/Fine.ts +399 -0
  108. package/src/types/fine/FineTemplate.ts +219 -0
  109. package/src/types/{PayedState.ts → fine/PayedState.ts} +2 -2
  110. package/src/types/fine/index.ts +3 -0
  111. package/src/types/index.ts +7 -18
  112. package/src/types/{Localization.ts → localization/Localization.ts} +7 -64
  113. package/src/types/localization/PluralLocalization.ts +32 -0
  114. package/src/types/{Pluralization.ts → localization/Pluralization.ts} +1 -0
  115. package/src/types/localization/ValueLocalization.ts +36 -0
  116. package/src/types/localization/index.ts +5 -0
  117. package/src/types/notification/InAppNotification.ts +184 -0
  118. package/src/types/notification/index.ts +1 -0
  119. package/src/types/{Person.ts → person/Person.ts} +3 -3
  120. package/src/types/{PersonProperties.ts → person/PersonProperties.ts} +8 -7
  121. package/src/types/{PersonSignInProperties.ts → person/PersonSignInProperties.ts} +13 -12
  122. package/src/types/person/index.ts +3 -0
  123. package/src/types/{Invitation.ts → team/Invitation.ts} +1 -1
  124. package/src/types/team/Team.ts +204 -0
  125. package/src/types/{UserRole.ts → team/TeamRole.ts} +19 -17
  126. package/src/types/team/index.ts +3 -0
  127. package/src/types/{NotificationProperties.ts → user/NotificationProperties.ts} +12 -3
  128. package/src/types/user/User.ts +451 -0
  129. package/src/types/user/index.ts +2 -0
  130. package/src/utils/StaticUnionTypeBuilder.ts +23 -0
  131. package/src/utils/index.ts +1 -0
  132. package/lib/src/firebase/FirebaseConfiguration.d.ts +0 -64
  133. package/lib/src/firebase/FirebaseConfiguration.js +0 -79
  134. package/lib/src/firebase/Firestore.d.ts +0 -201
  135. package/lib/src/firebase/Firestore.js +0 -244
  136. package/lib/src/firebase/FirestoreScheme.d.ts +0 -42
  137. package/lib/src/firebase/FirestoreScheme.js +0 -2
  138. package/lib/src/firebase/Messaging.d.ts +0 -90
  139. package/lib/src/firebase/Messaging.js +0 -2
  140. package/lib/src/firebase/checkAuthentication.d.ts +0 -38
  141. package/lib/src/firebase/checkAuthentication.js +0 -64
  142. package/lib/src/firebase/index.d.ts +0 -6
  143. package/lib/src/firebase/pushNotification.d.ts +0 -39
  144. package/lib/src/firebase/pushNotification.js +0 -88
  145. package/lib/src/functions/notification/subscribe.d.ts +0 -18
  146. package/lib/src/types/Configuration.d.ts +0 -46
  147. package/lib/src/types/Configuration.js +0 -51
  148. package/lib/src/types/Fine.d.ts +0 -71
  149. package/lib/src/types/Fine.js +0 -74
  150. package/lib/src/types/FineAmount.d.ts +0 -207
  151. package/lib/src/types/FineAmount.js +0 -238
  152. package/lib/src/types/FineTemplate.d.ts +0 -69
  153. package/lib/src/types/FineTemplate.js +0 -72
  154. package/lib/src/types/FineTemplateRepetition.d.ts +0 -87
  155. package/lib/src/types/FineTemplateRepetition.js +0 -103
  156. package/lib/src/types/Localization.js +0 -115
  157. package/lib/src/types/Team.d.ts +0 -62
  158. package/lib/src/types/Team.js +0 -64
  159. package/lib/src/types/User.d.ts +0 -221
  160. package/lib/src/types/User.js +0 -235
  161. package/lib/src/types/UserRole.d.ts +0 -29
  162. package/lib/test/firebase/FirebaseConfiguration.test.d.ts +0 -1
  163. package/lib/test/firebase/FirebaseConfiguration.test.js +0 -158
  164. package/lib/test/firebase/Firestore.test.d.ts +0 -1
  165. package/lib/test/firebase/Firestore.test.js +0 -46
  166. package/lib/test/firebase/checkAuthentication.test.d.ts +0 -1
  167. package/lib/test/firebase/checkAuthentication.test.js +0 -356
  168. package/lib/test/firebase/firebase-utils.d.ts +0 -32
  169. package/lib/test/firebase/firebase-utils.js +0 -134
  170. package/lib/test/firebase/pushNotification.test.d.ts +0 -1
  171. package/lib/test/firebase/pushNotification.test.js +0 -300
  172. package/lib/test/locales/localization.de.test.d.ts +0 -1
  173. package/lib/test/locales/localization.de.test.js +0 -144
  174. package/lib/test/locales/localization.en.test.d.ts +0 -1
  175. package/lib/test/locales/localization.en.test.js +0 -144
  176. package/lib/test/types/Configuration.test.d.ts +0 -1
  177. package/lib/test/types/Configuration.test.js +0 -84
  178. package/lib/test/types/Currency.test.d.ts +0 -1
  179. package/lib/test/types/Currency.test.js +0 -41
  180. package/lib/test/types/Fine.test.d.ts +0 -1
  181. package/lib/test/types/Fine.test.js +0 -265
  182. package/lib/test/types/FineAmount.test.d.ts +0 -1
  183. package/lib/test/types/FineAmount.test.js +0 -445
  184. package/lib/test/types/FineTemplate.test.d.ts +0 -1
  185. package/lib/test/types/FineTemplate.test.js +0 -271
  186. package/lib/test/types/FineTemplateRepetition.test.d.ts +0 -1
  187. package/lib/test/types/FineTemplateRepetition.test.js +0 -361
  188. package/lib/test/types/Invitation.test.d.ts +0 -1
  189. package/lib/test/types/Invitation.test.js +0 -269
  190. package/lib/test/types/Locale.test.d.ts +0 -1
  191. package/lib/test/types/Locale.test.js +0 -46
  192. package/lib/test/types/Localization.test.d.ts +0 -1
  193. package/lib/test/types/Localization.test.js +0 -241
  194. package/lib/test/types/MoneyAmount.test.d.ts +0 -1
  195. package/lib/test/types/MoneyAmount.test.js +0 -276
  196. package/lib/test/types/NotificationProperties.test.d.ts +0 -1
  197. package/lib/test/types/NotificationProperties.test.js +0 -258
  198. package/lib/test/types/PayedState.test.d.ts +0 -1
  199. package/lib/test/types/PayedState.test.js +0 -136
  200. package/lib/test/types/Person.test.d.ts +0 -1
  201. package/lib/test/types/Person.test.js +0 -266
  202. package/lib/test/types/PersonProperties.test.d.ts +0 -1
  203. package/lib/test/types/PersonProperties.test.js +0 -155
  204. package/lib/test/types/PersonSignInProperties.test.d.ts +0 -1
  205. package/lib/test/types/PersonSignInProperties.test.js +0 -208
  206. package/lib/test/types/Pluralization.test.d.ts +0 -1
  207. package/lib/test/types/Pluralization.test.js +0 -206
  208. package/lib/test/types/Team.test.d.ts +0 -1
  209. package/lib/test/types/Team.test.js +0 -145
  210. package/lib/test/types/User.test.d.ts +0 -1
  211. package/lib/test/types/User.test.js +0 -450
  212. package/lib/test/types/UserRole.test.d.ts +0 -1
  213. package/lib/test/types/UserRole.test.js +0 -140
  214. package/src/firebase/FirebaseConfiguration.ts +0 -99
  215. package/src/firebase/Firestore.ts +0 -258
  216. package/src/firebase/FirestoreScheme.ts +0 -41
  217. package/src/firebase/Messaging.ts +0 -93
  218. package/src/firebase/checkAuthentication.ts +0 -91
  219. package/src/firebase/index.ts +0 -7
  220. package/src/firebase/pushNotification.ts +0 -90
  221. package/src/functions/notification/subscribe.ts +0 -23
  222. package/src/types/Configuration.ts +0 -65
  223. package/src/types/Fine.ts +0 -100
  224. package/src/types/FineAmount.ts +0 -303
  225. package/src/types/FineTemplate.ts +0 -96
  226. package/src/types/FineTemplateRepetition.ts +0 -125
  227. package/src/types/Team.ts +0 -87
  228. package/src/types/User.ts +0 -302
  229. /package/lib/src/types/{Locale.d.ts → localization/Locale.d.ts} +0 -0
  230. /package/lib/src/types/{Locale.js → localization/Locale.js} +0 -0
  231. /package/src/types/{Locale.ts → localization/Locale.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
- import { Configuration } from './Configuration';
3
2
  import { Currency } from './Currency';
3
+ import { Locale } from './localization/Locale';
4
4
 
5
5
  /**
6
6
  * Represents a monetary amount with integer value and subunit components.
@@ -8,10 +8,10 @@ import { Currency } from './Currency';
8
8
  * Stores money as two parts: main value (e.g., dollars) and subunit value (e.g., cents).
9
9
  * This prevents floating-point precision issues in financial calculations.
10
10
  */
11
- export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
11
+ export class Money implements Flattable<Money.Flatten> {
12
12
 
13
13
  /**
14
- * Creates a new MoneyAmount instance.
14
+ * Creates a new Money instance.
15
15
  *
16
16
  * @param value - The main value (e.g., dollars, euros)
17
17
  * @param subunitValue - The subunit value (e.g., cents), should be 0-99
@@ -22,38 +22,38 @@ export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
22
22
  ) {}
23
23
 
24
24
  /**
25
- * Returns a MoneyAmount representing zero.
25
+ * Returns a Money instance representing zero.
26
26
  */
27
- public static get zero(): MoneyAmount {
28
- return new MoneyAmount(0, 0);
27
+ public static get zero(): Money {
28
+ return new Money(0, 0);
29
29
  }
30
30
 
31
31
  /**
32
- * Adds another MoneyAmount to this one and returns the result.
32
+ * Adds another Money instance to this one and returns the result.
33
33
  *
34
34
  * Properly handles subunit overflow (e.g., 50 cents + 60 cents = 1 dollar 10 cents).
35
35
  *
36
- * @param amount - The MoneyAmount to add
37
- * @returns A new MoneyAmount representing the sum
36
+ * @param amount - The Money instance to add
37
+ * @returns A new Money instance representing the sum
38
38
  */
39
- public added(amount: MoneyAmount): MoneyAmount {
39
+ public added(amount: Money): Money {
40
40
  const subunitValue = this.subunitValue + amount.subunitValue;
41
41
  const value = this.value + amount.value + Math.floor(subunitValue / 100);
42
- return new MoneyAmount(value, subunitValue % 100);
42
+ return new Money(value, subunitValue % 100);
43
43
  }
44
44
 
45
45
  /**
46
- * Multiplies this MoneyAmount by a factor and returns the result.
46
+ * Multiplies this Money instance by a factor and returns the result.
47
47
  *
48
48
  * Properly handles subunit calculations and overflow.
49
49
  *
50
50
  * @param factor - The multiplication factor
51
- * @returns A new MoneyAmount representing the product
51
+ * @returns A new Money instance representing the product
52
52
  */
53
- public multiplied(factor: number): MoneyAmount {
53
+ public multiplied(factor: number): Money {
54
54
  const subunitValue = this.subunitValue * factor;
55
55
  const value = this.value * factor + Math.floor(subunitValue / 100);
56
- return new MoneyAmount(value, subunitValue % 100);
56
+ return new Money(value, subunitValue % 100);
57
57
  }
58
58
 
59
59
  /**
@@ -62,11 +62,11 @@ export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
62
62
  * Uses Intl.NumberFormat for proper currency formatting based on locale.
63
63
  *
64
64
  * @param currency - The currency code (e.g., 'USD', 'EUR')
65
- * @param configuration - Configuration containing locale information
65
+ * @param locale - The locale information for formatting
66
66
  * @returns Formatted currency string (e.g., "$12.50", "12,50 €")
67
67
  */
68
- public formatted(currency: Currency, configuration: Configuration): string {
69
- const numberFormat = Intl.NumberFormat(configuration.locale, {
68
+ public formatted(currency: Currency, locale: Locale): string {
69
+ const numberFormat = Intl.NumberFormat(locale, {
70
70
  style: 'currency',
71
71
  currency: currency
72
72
  });
@@ -85,38 +85,38 @@ export class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
85
85
  /**
86
86
  * Returns the flattened representation as a decimal number.
87
87
  */
88
- public get flatten(): MoneyAmount.Flatten {
88
+ public get flatten(): Money.Flatten {
89
89
  return this.value + this.subunitValue / 100;
90
90
  }
91
91
  }
92
92
 
93
- export namespace MoneyAmount {
93
+ export namespace Money {
94
94
 
95
95
  /**
96
- * Flattened representation of MoneyAmount as a decimal number.
96
+ * Flattened representation of Money as a decimal number.
97
97
  */
98
98
  export type Flatten = number;
99
99
 
100
100
  /**
101
- * Type builder for MoneyAmount serialization/deserialization.
101
+ * Type builder for Money serialization/deserialization.
102
102
  */
103
- export class TypeBuilder implements ITypeBuilder<Flatten, MoneyAmount> {
103
+ export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
104
104
 
105
105
  /**
106
- * Builds a MoneyAmount instance from a flattened decimal value.
106
+ * Builds a Money instance from a flattened decimal value.
107
107
  *
108
108
  * Separates the decimal into integer and subunit parts.
109
109
  *
110
110
  * @param value - Decimal value (e.g., 12.50)
111
- * @returns MoneyAmount instance
111
+ * @returns Money instance
112
112
  */
113
- public build(value: Flatten): MoneyAmount {
114
- return new MoneyAmount(Math.floor(value), Math.round((value - Math.floor(value)) * 100));
113
+ public build(value: Flatten): Money {
114
+ return new Money(Math.floor(value), Math.round((value - Math.floor(value)) * 100));
115
115
  }
116
116
  }
117
117
 
118
118
  /**
119
- * Singleton instance of TypeBuilder for MoneyAmount.
119
+ * Singleton instance of TypeBuilder for Money.
120
120
  */
121
- export const builder = new MoneyAmount.TypeBuilder();
121
+ export const builder = new Money.TypeBuilder();
122
122
  }
@@ -0,0 +1,399 @@
1
+ import { Flattable, Guid, ITypeBuilder, Tagged, UtcDate, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
+ import { Money as MoneyValue } from '../Money';
3
+ import { Localization } from '../localization/Localization';
4
+ import { Locale } from '../localization/Locale';
5
+ import { Currency } from '../Currency';
6
+ import { PayedState } from './PayedState';
7
+
8
+ /**
9
+ * Represents a fine assigned to a person in a team.
10
+ *
11
+ * Contains information about the fine's payment status, date, reason, and monetary amount.
12
+ */
13
+ export class Fine implements Flattable<Fine.Flatten> {
14
+
15
+ /**
16
+ * Creates a new Fine instance.
17
+ *
18
+ * @param id - Unique identifier for the fine (GUID)
19
+ * @param payedState - Payment status ('payed' or 'notPayed')
20
+ * @param date - Date when the fine was issued
21
+ * @param reason - Description or reason for the fine
22
+ * @param amount - Monetary amount of the fine
23
+ */
24
+ public constructor(
25
+ public id: Fine.Id,
26
+ public payedState: PayedState,
27
+ public date: UtcDate,
28
+ public reason: string,
29
+ public amount: Fine.Amount
30
+ ) {}
31
+
32
+ /**
33
+ * Returns the flattened representation for serialization.
34
+ */
35
+ public get flatten(): Fine.Flatten {
36
+ return {
37
+ id: this.id.flatten,
38
+ payedState: this.payedState,
39
+ date: this.date.flatten,
40
+ reason: this.reason,
41
+ amount: this.amount.flatten
42
+ };
43
+ }
44
+ }
45
+
46
+ export namespace Fine {
47
+
48
+ /**
49
+ * Tagged GUID type for fine identifiers.
50
+ */
51
+ export type Id = Tagged<Guid, 'fine'>;
52
+
53
+ export namespace Id {
54
+
55
+ /**
56
+ * Flattened representation of a fine ID (GUID string).
57
+ */
58
+ export type Flatten = string;
59
+
60
+ /**
61
+ * Type builder for Fine.Id serialization/deserialization.
62
+ */
63
+ export const builder = Tagged.builder('fine' as const, Guid.builder);
64
+ }
65
+
66
+ /**
67
+ * Represents the amount of a fine.
68
+ *
69
+ * Can be either Fine.Amount.Money (e.g., $10) or Fine.Amount.Item (e.g., 2 crates of beer).
70
+ */
71
+ export type Amount =
72
+ | Amount.Money
73
+ | Amount.Item;
74
+
75
+ export namespace Amount {
76
+
77
+ /**
78
+ * Represents a fine amount as a monetary value.
79
+ */
80
+ export class Money implements Flattable<Money.Flatten> {
81
+
82
+ /**
83
+ * Creates a new monetary fine amount.
84
+ *
85
+ * @param amount - The monetary amount
86
+ */
87
+ public constructor(
88
+ public amount: MoneyValue
89
+ ) {}
90
+
91
+ /**
92
+ * Returns a formatted string representation of the amount.
93
+ *
94
+ * @param currency - The currency code
95
+ * @param locale - The locale for formatting
96
+ * @returns Formatted currency string (e.g., "$10.50")
97
+ */
98
+ public formatted(currency: Currency, locale: Locale): string {
99
+ return this.amount.formatted(currency, locale);
100
+ }
101
+
102
+ /**
103
+ * Returns a new Money instance with the amount multiplied by a factor.
104
+ *
105
+ * @param factor - The multiplication factor
106
+ * @returns New Money instance with multiplied amount
107
+ */
108
+ public multiplied(factor: number): Money {
109
+ return new Money(this.amount.multiplied(factor));
110
+ }
111
+
112
+ /**
113
+ * Returns the flattened representation for serialization.
114
+ */
115
+ public get flatten(): Money.Flatten {
116
+ return {
117
+ type: 'money',
118
+ amount: this.amount.flatten
119
+ };
120
+ }
121
+ }
122
+
123
+ export namespace Money {
124
+
125
+ /**
126
+ * Flattened representation of Money for serialization.
127
+ */
128
+ export type Flatten = {
129
+ type: 'money',
130
+ amount: MoneyValue.Flatten
131
+ }
132
+
133
+ /**
134
+ * Type builder for Money serialization/deserialization.
135
+ */
136
+ export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
137
+
138
+ /**
139
+ * Builds a Money instance from flattened data.
140
+ *
141
+ * @param value - Flattened money data
142
+ * @returns Money instance
143
+ */
144
+ public build(value: Flatten): Money {
145
+ return new Money(MoneyValue.builder.build(value.amount));
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Singleton instance of TypeBuilder for Money.
151
+ */
152
+ export const builder = new TypeBuilder();
153
+ }
154
+
155
+ /**
156
+ * Represents a fine amount as a quantity of items.
157
+ */
158
+ export class Item implements Flattable<Item.Flatten> {
159
+
160
+ /**
161
+ * Creates a new item fine amount.
162
+ *
163
+ * @param item - The item type (e.g., 'crateOfBeer')
164
+ * @param count - The number of items
165
+ */
166
+ public constructor(
167
+ public item: Item.Type,
168
+ public count: number
169
+ ) {}
170
+
171
+ /**
172
+ * Returns a formatted string representation including count.
173
+ *
174
+ * @param currency - The currency (unused for items, included for interface consistency)
175
+ * @param locale - The locale for formatting
176
+ * @returns Formatted string (e.g., "2 crates of beer")
177
+ */
178
+ public formatted(currency: Currency, locale: Locale): string {
179
+ return Localization.shared(locale).fineAmount.item.type[this.item].withCount.value(this.count);
180
+ }
181
+
182
+ /**
183
+ * Returns a formatted string representation without explicitly showing count.
184
+ *
185
+ * @param locale - The locale for formatting
186
+ * @returns Formatted string without count display
187
+ */
188
+ public formattedWithoutCount(locale: Locale): string {
189
+ return Localization.shared(locale).fineAmount.item.type[this.item].withoutCount.value(this.count);
190
+ }
191
+
192
+ /**
193
+ * Returns a new Item instance with the count multiplied by a factor.
194
+ *
195
+ * @param factor - The multiplication factor
196
+ * @returns New Item instance with multiplied count
197
+ */
198
+ public multiplied(factor: number): Item {
199
+ return new Item(this.item, this.count * factor);
200
+ }
201
+
202
+ /**
203
+ * Returns the flattened representation for serialization.
204
+ */
205
+ public get flatten(): Item.Flatten {
206
+ return {
207
+ type: 'item',
208
+ item: this.item,
209
+ count: this.count
210
+ };
211
+ }
212
+ }
213
+
214
+ export namespace Item {
215
+
216
+ const itemTypes = ['crateOfBeer'] as const;
217
+
218
+ /**
219
+ * Item type: currently only 'crateOfBeer'.
220
+ */
221
+ export type Type = typeof itemTypes[number];
222
+
223
+ export namespace Type {
224
+
225
+ /**
226
+ * Array containing all possible item types.
227
+ */
228
+ export const all: readonly Type[] = itemTypes;
229
+
230
+ /**
231
+ * Returns the localized name for an item type.
232
+ *
233
+ * @param type - The item type
234
+ * @param locale - The locale to use for formatting
235
+ * @returns Localized item name
236
+ */
237
+ export function formatted(type: Type, locale: Locale): string {
238
+ return Localization.shared(locale).fineAmount.item.type[type].name.value();
239
+ }
240
+
241
+ /**
242
+ * Type builder for Item.Type serialization/deserialization.
243
+ */
244
+ export const builder = new ValueTypeBuilder<Type>();
245
+ }
246
+
247
+ /**
248
+ * Flattened representation of Item for serialization.
249
+ */
250
+ export type Flatten = {
251
+ type: 'item',
252
+ item: Item.Type,
253
+ count: number
254
+ }
255
+
256
+ /**
257
+ * Type builder for Item serialization/deserialization.
258
+ */
259
+ export class TypeBuilder implements ITypeBuilder<Flatten, Item> {
260
+
261
+ /**
262
+ * Builds an Item instance from flattened data.
263
+ *
264
+ * @param value - Flattened item data
265
+ * @returns Item instance
266
+ */
267
+ public build(value: Flatten): Item {
268
+ return new Item(value.item, value.count);
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Singleton instance of TypeBuilder for Item.
274
+ */
275
+ export const builder = new TypeBuilder();
276
+ }
277
+
278
+ /**
279
+ * Creates a monetary fine amount.
280
+ *
281
+ * @param amount - The monetary amount
282
+ * @returns Money instance
283
+ */
284
+ export function money(amount: MoneyValue): Money {
285
+ return new Money(amount);
286
+ }
287
+
288
+ /**
289
+ * Creates an item fine amount.
290
+ *
291
+ * @param item - The item type
292
+ * @param count - The number of items
293
+ * @returns Item instance
294
+ */
295
+ export function item(item: Item.Type, count: number): Item {
296
+ return new Item(item, count);
297
+ }
298
+
299
+ /**
300
+ * Compares two fine amounts and returns their relative ordering.
301
+ *
302
+ * Money amounts are considered greater than Item amounts.
303
+ * Within the same type, values are compared numerically.
304
+ *
305
+ * @param lhs - First fine amount to compare
306
+ * @param rhs - Second fine amount to compare
307
+ * @returns 'less' if lhs < rhs, 'equal' if lhs === rhs, 'greater' if lhs > rhs
308
+ */
309
+ export function compare(lhs: Amount, rhs: Amount): 'less' | 'equal' | 'greater' {
310
+ if (lhs instanceof Money) {
311
+ if (!(rhs instanceof Money))
312
+ return 'greater';
313
+ const lhsAmount = lhs.amount.completeValue;
314
+ const rhsAmount = rhs.amount.completeValue;
315
+ if (lhsAmount !== rhsAmount)
316
+ return lhsAmount < rhsAmount ? 'less' : 'greater';
317
+ }
318
+ if (lhs instanceof Item) {
319
+ if (!(rhs instanceof Item))
320
+ return 'less';
321
+ if (lhs.count === rhs.count)
322
+ return 'equal';
323
+ return lhs.count < rhs.count ? 'less' : 'greater';
324
+ }
325
+ return 'equal';
326
+ }
327
+
328
+ /**
329
+ * Flattened representation of Amount (union of Money.Flatten and Item.Flatten).
330
+ */
331
+ export type Flatten = Money.Flatten | Item.Flatten;
332
+
333
+ /**
334
+ * Type builder for Amount serialization/deserialization.
335
+ */
336
+ export class TypeBuilder implements ITypeBuilder<Flatten, Amount> {
337
+
338
+ /**
339
+ * Builds an Amount instance from flattened data.
340
+ *
341
+ * Determines the type based on the 'type' discriminator field.
342
+ *
343
+ * @param value - Flattened fine amount data
344
+ * @returns Amount instance (Money or Item)
345
+ */
346
+ public build(value: Flatten): Amount {
347
+ switch (value.type) {
348
+ case 'money':
349
+ return Money.builder.build(value);
350
+ case 'item':
351
+ return Item.builder.build(value);
352
+ }
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Singleton instance of TypeBuilder for Amount.
358
+ */
359
+ export const builder = new TypeBuilder();
360
+ }
361
+
362
+ /**
363
+ * Flattened representation of a Fine for serialization.
364
+ */
365
+ export type Flatten = {
366
+ id: Id.Flatten,
367
+ payedState: PayedState,
368
+ date: UtcDate.Flatten,
369
+ reason: string,
370
+ amount: Amount.Flatten
371
+ };
372
+
373
+ /**
374
+ * Type builder for Fine serialization/deserialization.
375
+ */
376
+ export class TypeBuilder implements ITypeBuilder<Flatten, Fine> {
377
+
378
+ /**
379
+ * Builds a Fine instance from flattened data.
380
+ *
381
+ * @param value - Flattened fine data
382
+ * @returns Fine instance
383
+ */
384
+ public build(value: Flatten): Fine {
385
+ return new Fine(
386
+ Id.builder.build(value.id),
387
+ value.payedState,
388
+ UtcDate.builder.build(value.date),
389
+ value.reason,
390
+ Amount.builder.build(value.amount)
391
+ );
392
+ }
393
+ }
394
+
395
+ /**
396
+ * Singleton instance of TypeBuilder for Fine.
397
+ */
398
+ export const builder = new TypeBuilder();
399
+ }