/*
 * Copyright 2018 The RoboZonky Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.robozonky.api.remote.entities;

import java.math.BigDecimal;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;

public class Statistics extends BaseEntity {

    public static Statistics empty() {
        final Statistics s = new Statistics();
        s.currentProfitability = BigDecimal.ZERO;
        s.expectedProfitability = BigDecimal.ZERO;
        s.cashFlow = Collections.emptyList();
        s.riskPortfolio = Collections.emptyList();
        s.currentOverview = new CurrentOverview();
        s.overallOverview = new OverallOverview();
        s.overallPortfolio = new OverallPortfolio();
        s.superInvestorOverview = SuperInvestorOverview.empty();
        s.timestamp = OffsetDateTime.now();
        return s;
    }

    private BigDecimal currentProfitability, expectedProfitability;
    private CurrentOverview currentOverview;
    private OverallOverview overallOverview;
    private OverallPortfolio overallPortfolio;
    private SuperInvestorOverview superInvestorOverview;
    private List<RiskPortfolio> riskPortfolio;
    private List<Instalment> cashFlow;
    private OffsetDateTime timestamp;

    private Statistics() {
        // for JAXB
    }

    @XmlElement
    public BigDecimal getCurrentProfitability() {
        return currentProfitability;
    }

    @XmlElement
    public BigDecimal getExpectedProfitability() {
        return expectedProfitability;
    }

    @XmlElement
    public CurrentOverview getCurrentOverview() {
        return currentOverview;
    }

    @XmlElement
    public OverallOverview getOverallOverview() {
        return overallOverview;
    }

    @XmlElement
    public OverallPortfolio getOverallPortfolio() {
        return overallPortfolio;
    }

    @XmlElement
    public List<RiskPortfolio> getRiskPortfolio() {
        return Collections.unmodifiableList(riskPortfolio);
    }

    @XmlElement
    public SuperInvestorOverview getSuperInvestorOverview() {
        return superInvestorOverview;
    }

    @XmlElement
    public List<Instalment> getCashFlow() {
        return Collections.unmodifiableList(cashFlow);
    }

    @XmlElement
    public OffsetDateTime getTimestamp() {
        return timestamp;
    }
}

@@ -857,16 +857,457 @@
 tity %7B%0A%0A
+    private BigDecimal currentProfitability, expectedProfitability;%0A    private CurrentOverview currentOverview;%0A    private OverallOverview overallOverview;%0A    private OverallPortfolio overallPortfolio;%0A    private SuperInvestorOverview superInvestorOverview;%0A    private List%3CRiskPortfolio%3E riskPortfolio;%0A    private List%3CInstalment%3E cashFlow;%0A    private OffsetDateTime timestamp;%0A%0A    private Statistics() %7B%0A        // for JAXB%0A    %7D%0A%0A
     publ
@@ -1333,24 +1333,24 @@
 s empty() %7B%0A
-
         fina
@@ -1887,429 +1887,184 @@
 ate 
-BigDecimal currentPro
+static %3CT%3E List%3CT%3E unmodi
 fi
-t
 ab
-ility, expectedProfitability;%0A    private CurrentOverview currentOverview;%0A    private OverallOverview overallOverview;%0A    private OverallPortfolio overallPortfolio;%0A    private SuperInvestorOverview superInvestorOverview;%0A    private List%3CRiskPortfolio%3E riskPortfolio;%0A    private List%3CInstalment%3E cashFlow;%0A    private OffsetDateTime timestamp;%0A%0A    private Statistics() %7B%0A        // for JAXB
+leOrEmpty(final List%3CT%3E possiblyNull) %7B%0A        return possiblyNull == null ? Collections.emptyList() : Collections.unmodifiableList(possiblyNull);
 %0A   
@@ -2666,32 +2666,79 @@
 iskPortfolio() %7B
+ // %22riskPortfolio%22 is null for new Zonky users
 %0A        return 
@@ -2733,36 +2733,24 @@
      return 
-Collections.
 unmodifiable
@@ -2749,20 +2749,23 @@
 difiable
-List
+OrEmpty
 (riskPor
@@ -2978,28 +2978,16 @@
  return 
-Collections.
 unmodifi
@@ -2990,20 +2990,23 @@
 difiable
-List
+OrEmpty
 (cashFlo

Fix NPE when null portfolio returned from Zonky (closes #235)