package output.feed;

import lombok.Data;

import java.util.Map;

@Data
public class GoogleFeed extends AdFeed {
    private String title;
    private String description;
    private String link;
    private String image_link;
    private String availability;
    private String google_product_category;
    private String price;

    public GoogleFeed(
        String id,
        String title,
        String description,
        String link,
        String image_link,
        String availability,
        String price,
        String google_product_category) {

        validateAndAssign(id, title, description, link, image_link, availability, price, google_product_category);
    }

    public GoogleFeed(Map<String, String> data) {
        String id = data.get("id");
        String title = data.get("title");
        String description = data.get("description");
        String link = data.get("link");
        String image_link = data.get("image_link");
        String availability = data.get("availability");
        String price = data.get("price");
        String google_product_category = data.get("google_product_category");

        validateAndAssign(id, title, description, link, image_link, availability, price, google_product_category);
    }

    private void validateAndAssign(String id, String title, String description, String link, String imageLink, String availability, String price, String google_product_category) {
        validateLength(id, 50);
        this.id = id;

        validateLength(title, 150);
        this.title = title;

        validateLength(description, 5000);
        this.description = description;

        validateLength(link, 2000);
        this.link = link;

        validateLength(imageLink, 2000);
        this.image_link = imageLink;

        validateAvailability(availability);
        this.availability = availability;

        this.google_product_category = google_product_category;

        validatePrice(price);
        this.price = price;
    }

    private void validateLength(String value, int maxLength) {
//        if(value.length() > maxLength) {
//            throw new IllegalArgumentException("String of value " + value + " longer than " + maxLength);
//        }
    }

    private void validateAvailability(String value) {
//        if (!value.equals("in stock") || !value.equals("out of stock") || !value.equals("preorder")) {
//            throw new IllegalArgumentException("Value " + value + " not valid for availability field");
//        }
    }

    private void validatePrice(String value) {
//        String currCode = value.substring(value.length() - 3, value.length() - 1);
//        if(Currency.getInstance(currCode) == null) {
//            throw new IllegalArgumentException("Invalid currency code " + currCode + " in price string " + value);
//        }
    }
}

@@ -36,16 +36,43 @@
 .Data;%0A%0A
+import java.util.Currency;%0A
 import j
@@ -355,364 +355,8 @@
 e;%0A%0A
-    public GoogleFeed(%0A        String id,%0A        String title,%0A        String description,%0A        String link,%0A        String image_link,%0A        String availability,%0A        String price,%0A        String google_product_category) %7B%0A%0A        validateAndAssign(id, title, description, link, image_link, availability, price, google_product_category);%0A    %7D%0A%0A
     
@@ -1722,34 +1722,32 @@
 nt maxLength) %7B%0A
-//
         if(value
@@ -1740,16 +1740,17 @@
       if
+ 
 (value.l
@@ -1768,26 +1768,24 @@
 axLength) %7B%0A
-//
             
@@ -1878,18 +1878,16 @@
 ength);%0A
-//
         
@@ -1941,34 +1941,32 @@
 String value) %7B%0A
-//
         if (!val
@@ -1962,16 +1962,17 @@
    if (!
+(
 value.eq
@@ -1983,33 +1983,32 @@
 (%22in stock%22) %7C%7C 
-!
 value.equals(%22ou
@@ -2023,17 +2023,16 @@
 ck%22) %7C%7C 
-!
 value.eq
@@ -2048,21 +2048,20 @@
 order%22))
+)
  %7B%0A
-//
         
@@ -2156,18 +2156,16 @@
 ield%22);%0A
-//
         
@@ -2216,26 +2216,24 @@
 ng value) %7B%0A
-//
         Stri
@@ -2300,17 +2300,11 @@
 th()
- - 1
 );%0A
-//
     
@@ -2309,16 +2309,17 @@
       if
+ 
 (Currenc
@@ -2353,18 +2353,16 @@
 null) %7B%0A
-//
         
@@ -2472,10 +2472,8 @@
 e);%0A
-//
     

Add ability to statically define data