11package me .smartstore .group ;
22
3+ import me .smartstore .customer .CustomerRepository ;
34import me .smartstore .menu .exception .InvalidGroupNameException ;
45
56import java .util .Arrays ;
@@ -11,6 +12,10 @@ public enum Group {
1112 VIP ("V" ),
1213 VVIP ("VV" );
1314
15+ private static final Group [] USED_GROUPS = { GENERAL , VIP , VVIP };
16+ private static GroupParameter tempParameter ;
17+ private static Group tempGroup ;
18+
1419 private final String shortcut ;
1520 private final GroupParameter groupParameter ;
1621
@@ -19,9 +24,11 @@ public enum Group {
1924 this .groupParameter = new GroupParameter ();
2025 }
2126
27+ public static Group [] getUsedGroups () { return USED_GROUPS ; }
28+
2229 public static Group getGroupByString (String s ) throws InvalidGroupNameException {
23- Group [] groups = Group .values ();
24- return Arrays .stream (groups , 1 , groups . length )
30+ Group [] groups = Group .getUsedGroups ();
31+ return Arrays .stream (groups )
2532 .filter (group -> group .isName (s ))
2633 .findAny ()
2734 .orElseThrow (() -> new InvalidGroupNameException ("\n Invalid Group Name for Input. Please try again.\n " ));
@@ -37,9 +44,9 @@ public void setGroupParameter(Integer[] groupParameterArguments) {
3744 }
3845
3946 public static Group calculate (Integer spentHours , Integer totalPaidAmount ) {
40- Group [] groups = values ();
47+ Group [] groups = getUsedGroups ();
4148 Group ret = NONE ;
42- int i = 1 ;
49+ int i = 0 ;
4350 for (; i < groups .length ; ++i ) {
4451 Group group = groups [i ];
4552 GroupParameter parameter = group .groupParameter ;
@@ -56,9 +63,43 @@ public static Group calculate(Integer spentHours, Integer totalPaidAmount) {
5663 return ret ;
5764 }
5865
66+ public static void setTempMinSpentHours (Integer minSpentHours ) {
67+ tempParameter .setMinSpentHours (minSpentHours );
68+ }
69+
70+ public static void setTempMinTotalPaidAmount (Integer minTotalPaidAmount ) {
71+ tempParameter .setMinTotalPaidAmount (minTotalPaidAmount );
72+ }
73+
74+ public static void setTempParameter (Group group ) {
75+ GroupParameter param = group .groupParameter ;
76+ tempParameter = new GroupParameter (param .getMinSpentHours (), param .getMinTotalPaidAmount ());
77+ tempGroup = group ;
78+ }
79+
80+ public static String getUpdateBeforeAndAfterInfo () {
81+ String before = tempGroup .groupParameter .toString ();
82+ String after = tempParameter .toString ();
83+ return getGroupNameInfo (tempGroup ) +
84+ "Before: " + before + '\n' +
85+ "After : " + after ;
86+ }
87+
88+ public static void updateGroupParameter () {
89+ GroupParameter param = tempGroup .groupParameter ;
90+ param .setMinSpentHours (tempParameter .getMinSpentHours ());
91+ param .setMinTotalPaidAmount (tempParameter .getMinTotalPaidAmount ());
92+
93+ CustomerRepository .getInstance ().updateGroupIn (tempGroup );
94+ }
95+
5996 @ Override
6097 public String toString () {
61- return " \n GroupType: " + this . name () + '\n'
98+ return getGroupNameInfo ( this )
6299 + "Parameter: " + this .groupParameter + '\n' ;
63100 }
101+
102+ public static String getGroupNameInfo (Group group ) {
103+ return '\n' + "Group: " + group .name () + '\n' ;
104+ }
64105}
0 commit comments