/*
 * This file is part of mobuk.
 *
 * Plan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * Plan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNUKS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with mobuk.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.tenuki.mobuk.ext.uk.vodafone.particulares;

import java.util.ArrayList;

import com.tenuki.mobuk.core.Chargeable;
import com.tenuki.mobuk.core.call.Call;
import com.tenuki.mobuk.core.message.ChargeableMessage;
import com.tenuki.mobuk.core.msisdn.MsisdnType;
import com.tenuki.mobuk.core.plan.PlanChargeable;
import com.tenuki.mobuk.core.plan.PlanSummary;
import com.tenuki.mobuk.core.sms.Sms;
import com.tenuki.mobuk.ext.uk.vodafone.UKVodafone;


/**
 * Vodafone @L.
 *
 * @author sanz
 */
public class UKVodafone12months46 extends UKVodafone {
    
	private double monthFee = 46;
	private double initialPrice = 0.00;
	private double pricePerSecond = 0.35/ 60;
	private double smsPrice = 0.0;
	private int maxSecondsMonth = 900 * 60;
	private int maxFreeSMS = 30000;
private double internet = 0;
    
	public String getPlanName() {
		return "46 pounds (12mon)";
	}
	
	public String getPlanURL() {
		return "http://shop.vodafone.co.uk/shop/mobile-price-plans/all-plans?initialFilters=flt_12monthplans";
	}
	
	public PlanSummary process(ArrayList<Chargeable> data) {
		PlanSummary ret = new PlanSummary(this);
		ret.addPlanCall(new PlanChargeable(new ChargeableMessage(ChargeableMessage.MESSAGE_MONTH_FEE), monthFee, this.getCurrency()));
		int smsSent = 0;
		int secondsTotal = 0;
		for (Chargeable chargeable : data) {
			if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_CALL) {
				Call call = (Call) chargeable;
			
				if (call.getType() != Call.CALL_TYPE_SENT) {
					continue;
				}
				
				double callPrice = 0;
				
				if (call.getContact().getMsisdnType() == MsisdnType.UK_SPECIAL_ZER0) {
					callPrice = 0;
				} else {
					secondsTotal += call.getDuration();
					boolean insidePlan = secondsTotal <= maxSecondsMonth;
					if (!insidePlan) {
						long duration = (secondsTotal > maxSecondsMonth) && (secondsTotal - call.getDuration() <= maxSecondsMonth)? secondsTotal - maxSecondsMonth : call.getDuration();  
						callPrice += initialPrice + (duration * pricePerSecond);
					}
				}
				ret.addPlanCall(new PlanChargeable(call, callPrice, this.getCurrency()));
			} else if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_SMS) {
				Sms sms = (Sms) chargeable;
				if (sms.getType() == Sms.SMS_TYPE_RECEIVED) {
					continue;
				}
				smsSent++;
				ret.addPlanCall(new PlanChargeable(chargeable, (smsSent > maxFreeSMS)?smsPrice:0, this.getCurrency()));
			}
		}
		return ret;
	}
}