package sizebay.catalog.client.model;

import com.fasterxml.jackson.annotation.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.UUID;
import static java.time.LocalDateTime.now;

@Data
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Profile implements Serializable {

     private static final BigDecimal DAYS_OF_YEAR = new BigDecimal(365.2425D);

     long id;
     String userId;
     String name;
     String gender;
     int age;
     int weight;
     double height;
     int bodyShapeChest;
     int bodyShapeWaist;
     int bodyShapeHip;
     int footShape;
     int skinType;
     boolean ignoreGender;

     int isActive;
     long lastActiveTime;

     @JsonProperty("is3dFeel")
		 boolean is3dFeel;

     ProfileMeasurements measures;
     ProfileProduct product;

    @JsonGetter
    public String getIdView() {return Long.toString(this.id);}

     public Date getBirth(int age) {
          final int days = new BigDecimal(age).multiply(DAYS_OF_YEAR).intValue();
          final ZonedDateTime then = now().minusDays(days).atZone(ZoneId.systemDefault());

          return ( Date.from(then.toInstant()));
     }

     public void generateIdentifier() {
          long val;
          do {
               val = UUID.randomUUID().getMostSignificantBits();
          } while (val < 0);
          this.setId(val);
     }

     public String getAgeGroup(final String productAgeGroup) {
    		final boolean isGrayZone = this.getAge() >= 12 && this.getAge() <= 16;

    		if(isGrayZone && productAgeGroup != null) {
					try {
					} catch (IllegalArgumentException e) {
                        return Product.AgeGroupEnum.valueOf(productAgeGroup.toUpperCase()).name();
					}
				}

				if(this.getAge() > 13) {
					return Product.AgeGroupEnum.ADULT.name();
				}

				return Product.AgeGroupEnum.KIDS.name();
		 }

}

@@ -1573,25 +1573,24 @@
      %7D%0A%0A    
- 
 public Strin
@@ -1639,18 +1639,20 @@
 ) %7B%0A    
-%09%09
+    
 final bo
@@ -1719,20 +1719,23 @@
 6;%0A%0A    
+ 
-%09%09
+   
 if
+ 
 (isGrayZ
@@ -1772,71 +1772,20 @@
 ) %7B%0A
-%09%09%09%09%09try %7B%0A%09%09%09%09%09%7D catch (IllegalArgumentException e) %7B%0A
+    
         
     
@@ -1772,32 +1772,38 @@
 ) %7B%0A            
+try %7B%0A
                 
@@ -1881,28 +1881,124 @@
 ();%0A
-%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%0A%09%09%09%09
+            %7D catch (IllegalArgumentException e) %7B%0A                return null;%0A            %7D%0A        %7D%0A%0A        
 if
+ 
 (thi
@@ -2020,13 +2020,20 @@
 ) %7B%0A
-%09%09%09%09%09
+            
 retu
@@ -2074,19 +2074,27 @@
 ();%0A
-%09%09%09%09%7D%0A%0A%09%09%09%09
+        %7D%0A%0A        
 retu
@@ -2134,12 +2134,12 @@
 ();%0A
-%09%09
+   
  %7D%0A
-%0A
 %7D%0A

format getAgeGroup on Profile