package com.wildcard.pair.model.search;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.wildcard.pair.model.Card;
import com.wildcard.pair.model.CardType;
import com.wildcard.pair.model.product.ProductCardBuilder;
import com.wildcard.pair.util.CardSerializer;
import com.wildcard.pair.util.ValidationTool;

import java.io.IOException;
import java.util.List;

/**
 * Created by michaelgarate on 6/16/14.
 */

public class ProductSearchCard implements Card {

    private CardType cardType;
    private Integer totalResults;
    private List<SearchProduct> products;

    public ProductSearchCard(List<SearchProduct> products, Integer totalResults){
        ValidationTool.notNull(products, "Must supply a list of products.");
        ValidationTool.notNull(totalResults, "Must supply a value for totalResults.");
        ValidationTool.notNegative(totalResults, "totalResults must be a positive Integer.");

        cardType = CardType.PRODUCT_SEARCH;
        this.products = products;
        this.totalResults = totalResults;
    }

    public Integer getTotalResults(){
        return totalResults;
    }

    public List<SearchProduct> getProducts(){
        return products;
    }

    @Override
    public String writeAsJsonString() throws IOException {
        return CardSerializer.writeCardAsString(this);
    }

    public CardType getCardType() {
        return cardType;
    }


    /*
     * The following private constructor and private methods are required by Jackson.
     */
    private ProductSearchCard(){}

    private void setTotalResults(Integer totalResults){
        this.totalResults = totalResults;
    }

    private void setCardType(CardType cardType){
        this.cardType = CardType.PRODUCT_SEARCH;
    }

    private void setProducts(List<SearchProduct> products){
        this.products = products;
    }
}

@@ -683,278 +683,20 @@
     
-ValidationTool.notNull(products, %22Must supply a list of products.%22);%0A        ValidationTool.notNull(totalResults, %22Must supply a value for totalResults.%22);%0A        ValidationTool.notNegative(totalResults, %22totalResults must be a positive Integer.%22);%0A%0A        c
+setC
 ardType
- = 
+(
 Card
@@ -710,24 +710,25 @@
 ODUCT_SEARCH
+)
 ;%0A        th
@@ -729,32 +729,28 @@
     
-this.p
+setP
 roducts
- = 
+(
 products
 ;%0A  
@@ -741,24 +741,25 @@
 cts(products
+)
 ;%0A        th
@@ -748,38 +748,36 @@
 ducts);%0A        
-this.t
+setT
 otalResults = to
@@ -763,35 +763,33 @@
  setTotalResults
- = 
+(
 totalResults;%0A  
@@ -776,32 +776,33 @@
 lts(totalResults
+)
 ;%0A    %7D%0A%0A    pub
@@ -1334,32 +1334,213 @@
  totalResults)%7B%0A
+        ValidationTool.notNull(totalResults, %22Must supply a value for totalResults.%22);%0A        ValidationTool.notNegative(totalResults, %22totalResults must be a positive Integer.%22);%0A
         this.tot
@@ -1669,32 +1669,32 @@
 _SEARCH;%0A    %7D%0A%0A
-
     private void
@@ -1733,24 +1733,101 @@
  products)%7B%0A
+        ValidationTool.notNull(products, %22Must supply a list of products.%22);%0A
         this

create product search setters