/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ScheduleUtil;

import InitialSchedules.ParametersInitialSchedules;
/**
 *
 * @author frabe
 */
public class EmployeeCostCalculator {
    
    public static int getFullScheduleCost( SchedulesArray mySchedule, ParametersInitialSchedules myScheduleParameters) {
        int totalCost = 0;
        for (int i = 0 ; i < mySchedule.getNumberPartTimeEmployee() ; i++) {
            totalCost += getPartTimeEmployeeCost(mySchedule.partTimeSchedules[i], myScheduleParameters);
        }
        for (int i = 0 ; i < mySchedule.getNumberFullTimeEmployee() ; i++) {
            totalCost += getFullTimeEmployeeCost(mySchedule.fullTimeSchedules[i], myScheduleParameters);
        }
        return totalCost;
    }
    //Dans cette classe, toutes les fonctions sont dedoublees. On devrait faire du polymorphisme et mettre ces fonctions dans les nouvelles classes schedules crees.
    public static int getPartTimeEmployeeCost( boolean[] employeeSchedule, ParametersInitialSchedules myScheduleParameters) {
        
        int consecutiveWorkingPeriods = 0;
        int overtimeWorkingPeriods = 0;
        int totalWorkingPeriods = 0;
        for (int workPeriod = 0; workPeriod < employeeSchedule.length ; workPeriod++) {
            if (employeeSchedule[workPeriod]) {
                totalWorkingPeriods += 1;
                consecutiveWorkingPeriods += 1;
                if (consecutiveWorkingPeriods > myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerShiftWork()) {
                    overtimeWorkingPeriods += 1;
                }
            } else {
                consecutiveWorkingPeriods = 0;
            }
        }
        
        int additionalOvertimeWorkingPeriods = totalWorkingPeriods - myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule();
        if ( additionalOvertimeWorkingPeriods > 0 ){
            overtimeWorkingPeriods += additionalOvertimeWorkingPeriods;
        }
        
        int employeeCost = myScheduleParameters.getFixedCostOfPartTimeEmployeesPerSchedule() + 
                overtimeWorkingPeriods * myScheduleParameters.getWorkingPeriodCostOfPartTimeEmployeesPaidAtOvertimeHourlyRate() +
                (totalWorkingPeriods - overtimeWorkingPeriods) * myScheduleParameters.getWorkingPeriodCostOfPartTimeEmployeesPaidAtRegularHourlyRate();
        
        return employeeCost;
    }
    
    public static int getFullTimeEmployeeCost( boolean[] employeeSchedule, ParametersInitialSchedules myScheduleParameters) {
       
        int consecutiveWorkingPeriods = 0;
        int overtimeWorkingPeriods = 0;
        int totalWorkingPeriods = 0;
        for (int workPeriod = 0; workPeriod < employeeSchedule.length ; workPeriod++) {
            if (employeeSchedule[workPeriod]) {
                totalWorkingPeriods += 1;
                consecutiveWorkingPeriods += 1;
                if (consecutiveWorkingPeriods > myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerShiftWork()) {
                    overtimeWorkingPeriods += 1;
                }
            } else {
                consecutiveWorkingPeriods = 0;
            }
        }
        
        int additionalOvertimeWorkingPeriods = totalWorkingPeriods - myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule();
        if ( additionalOvertimeWorkingPeriods > 0 ){
            overtimeWorkingPeriods += additionalOvertimeWorkingPeriods;
        }
        
        int employeeCost = myScheduleParameters.getFixedCostOfPartTimeEmployeesPerSchedule() + 
                overtimeWorkingPeriods * myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtOvertimeHourlyRate() +
                (totalWorkingPeriods - overtimeWorkingPeriods) * myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
        
        return employeeCost;
    }
}
