package com.akikanellis.kata01;

import com.akikanellis.kata01.item.Items;
import com.akikanellis.kata01.item.QuantifiedItem;
import com.akikanellis.kata01.offer.Offer;
import com.akikanellis.kata01.offer.OfferStrategy;
import com.akikanellis.kata01.offer.Offers;
import com.akikanellis.kata01.offer.QuantifiedOffer;
import com.akikanellis.kata01.price.Price;

public class TenPercentOffEverything extends OfferStrategy {

    private TenPercentOffEverything(long id) { super(id, "10% off everything"); }

    public static OfferStrategy create(int id) { return new TenPercentOffEverything(id); }

    @Override public Offers calculateOffers(Items items) {
        Price itemsPrice = items.stream()
                .map(QuantifiedItem::totalPrice)
                .reduce(Price::add)
                .orElse(Price.ZERO);

        Price discount = itemsPrice.multiplyBy(0.10).negate();
        Offer offer = Offer.create(description(), discount);
        QuantifiedOffer quantifiedOffer = QuantifiedOffer.create(offer, 1);

        return Offers.fromSingle(quantifiedOffer);
    }
}

@@ -354,16 +354,116 @@
 Price;%0A%0A
+/**%0A * An example offer strategy used for testing where all of our items are discounted by 10%25.%0A */%0A
 public c
@@ -514,16 +514,68 @@
 rategy %7B
+%0A    private static final double TEN_PERCENT = 0.10;
 %0A%0A    pr
@@ -825,16 +825,21 @@
 tems
+Total
 Price = 
 item
@@ -838,61 +838,23 @@
 e = 
-items.stream()%0A                .map(Quantified
+calculate
 Item
-::t
+sT
 otal
@@ -862,84 +862,17 @@
 rice
-)%0A                .reduce(Price::add)%0A                .orElse(Price.ZERO
+(items
 );%0A
-%0A
     
@@ -897,16 +897,21 @@
  = items
+Total
 Price.mu
@@ -919,20 +919,27 @@
 tiplyBy(
-0.10
+TEN_PERCENT
 ).negate
@@ -942,16 +942,17 @@
 gate();%0A
+%0A
         
@@ -1137,11 +1137,228 @@
 );%0A    %7D
+%0A%0A    private Price calculateItemsTotalPrice(Items items) %7B%0A        return items.stream()%0A                .map(QuantifiedItem::totalPrice)%0A                .reduce(Price::add)%0A                .orElse(Price.ZERO);%0A    %7D
 %0A%7D%0A

Refactor ten percent off everything strategy