package de.sondabar.model;

import com.google.cloud.dataflow.sdk.coders.AvroCoder;
import com.google.cloud.dataflow.sdk.coders.DefaultCoder;
import org.apache.avro.reflect.Nullable;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

@DefaultCoder(AvroCoder.class)
public class CampaignResult extends CampaignEvent {

    @Nullable
    private List<Feature> features;

    public enum State {
        Bid, WonBid, Impression, VisibleImpression, Click, Conversion
    }

    private State state = State.Bid;

    @Nullable
    private BigDecimal bidPrice;

    @Nullable
    private BigDecimal winPrice;

    public CampaignResult() {
    }

    public CampaignResult(Bid bid, WonBid wonBid) {
        this.bid = bid.bid;
        this.cid = bid.cid;
        this.bidPrice = bid.bidPrice;
        this.timestamp = bid.timestamp;
        this.features = new ArrayList<>(bid.features);
        if (wonBid != null) {
            winPrice = wonBid.getPrice();
        }
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    @Override
    public String toString() {
        return "CampaignResult{" +
                "features=" + features +
                ", state=" + state +
                ", bidPrice=" + bidPrice +
                ", winPrice=" + winPrice +
                '}';
    }
}

@@ -209,40 +209,8 @@
 al;%0A
-import java.text.DecimalFormat;%0A
 impo
@@ -233,16 +233,16 @@
 ayList;%0A
+
 import j
@@ -617,17 +617,17 @@
 ecimal w
-i
+o
 nPrice;%0A
@@ -948,17 +948,17 @@
        w
-i
+o
 nPrice =
@@ -1225,16 +1225,82 @@
        %22
+bid=%22 + bid +%0A                %22, cid=%22 + cid +%0A                %22, 
 features
@@ -1415,17 +1415,17 @@
     %22, w
-i
+o
 nPrice=%22
@@ -1428,17 +1428,17 @@
 ce=%22 + w
-i
+o
 nPrice +

improve toString()