/*
 * Copyright 2010-2011 Ning, Inc.
 *
 * Ning licenses this file to you 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.ning.billing.analytics;

import java.math.BigDecimal;
import java.util.Date;

import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.catalog.api.IDuration;
import com.ning.billing.catalog.api.IInternationalPrice;
import com.ning.billing.catalog.api.IPlan;
import com.ning.billing.catalog.api.IPlanPhase;
import com.ning.billing.catalog.api.IPrice;
import com.ning.billing.catalog.api.PhaseType;

public class MockPhase implements IPlanPhase
{
    private final PhaseType cohort;
    private final IPlan plan;
    private final IDuration duration;
    private final double price;

    public MockPhase(final PhaseType cohort, final IPlan plan, final IDuration duration, final double price)
    {
        this.cohort = cohort;
        this.plan = plan;
        this.duration = duration;
        this.price = price;
    }

    @Override
    public IInternationalPrice getRecurringPrice()
    {
        return new IInternationalPrice()
        {
            @Override
            public IPrice[] getPrices()
            {
                throw new UnsupportedOperationException();
            }

            @Override
            public BigDecimal getPrice(final Currency currency)
            {
                return BigDecimal.valueOf(price);
            }

			@Override
			public Date getEffectiveDateForExistingSubscriptons() {
				return new Date();
			}
        };
    }

    @Override
    public IInternationalPrice getFixedPrice()
    {
        return new IInternationalPrice()
        {
            @Override
            public IPrice[] getPrices()
            {
                throw new UnsupportedOperationException();
            }

            @Override
            public BigDecimal getPrice(final Currency currency)
            {
                return BigDecimal.valueOf(price);
            }
            
			@Override
			public Date getEffectiveDateForExistingSubscriptons() {
				return new Date();
			}
        };
    }

    @Override
    public BillingPeriod getBillingPeriod()
    {
        return BillingPeriod.MONTHLY;
    }

    @Override
    public String getName()
    {
        return plan.getName() + "-" + cohort;
    }

    @Override
    public IPlan getPlan()
    {
        return plan;
    }

    @Override
    public IDuration getDuration()
    {
        return duration;
    }

    @Override
    public PhaseType getPhaseType()
    {
        return cohort;
    }
}

@@ -658,61 +658,8 @@
 s;%0A%0A
-import java.math.BigDecimal;%0Aimport java.util.Date;%0A%0A
 impo
@@ -705,16 +705,16 @@
 Period;%0A
+
 import c
@@ -1038,16 +1038,69 @@
 eType;%0A%0A
+import java.math.BigDecimal;%0Aimport java.util.Date;%0A%0A
 public c
@@ -1952,32 +1952,50 @@
      %7D%0A%0A
-%09%09%09@Override%0A%09%09%09
+            @Override%0A            
 public D
@@ -2031,39 +2031,63 @@
 ngSubscriptons()
- %7B%0A%09%09%09%09
+%0A            %7B%0A                
 return new Date(
@@ -2081,35 +2081,44 @@
 urn new Date();%0A
-%09%09%09
+            
 %7D%0A        %7D;%0A   
@@ -2545,32 +2545,33 @@
 ;%0A            %7D%0A
+%0A
             %0A%09%09%09
@@ -2566,20 +2566,16 @@
         
-%0A%09%09%09
 @Overrid
@@ -2576,19 +2576,28 @@
 verride%0A
-%09%09%09
+            
 public D
@@ -2645,15 +2645,39 @@
 ns()
- %7B%0A%09%09%09%09
+%0A            %7B%0A                
 retu
@@ -2695,11 +2695,20 @@
 ();%0A
-%09%09%09
+            
 %7D%0A  
@@ -2872,32 +2872,114 @@
 getName()%0A    %7B%0A
+        if (plan == null) %7B%0A            return null;%0A        %7D%0A        else %7B%0A    
         return p
@@ -3004,24 +3004,34 @@
 %22 + cohort;%0A
+        %7D%0A
     %7D%0A%0A    @

fix potential NPE in MockPhase