/*
 * 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 AbsenceSchedules.AbsenceSchedulesArray;
import InitialSchedules.ParametersInitialSchedules;
import SchedulesRecovery.RecoveredSchedulesArray;
import VariableDemandSchedules.VariableDemandSchedulesArray;

/**
 *
 * @author frabe
 */
public class EmployeeCostCalculator {
    
    public static int getFullInitialScheduleCost( SchedulesArray myInitialSchedule, ParametersInitialSchedules myScheduleParameters) {
        int totalCost = 0;
        for (int partTimeEmployee = 0 ; partTimeEmployee < myInitialSchedule.getNumberPartTimeEmployee() ; partTimeEmployee++) {
            int numberWorkingPeriod = myInitialSchedule.getWorkingPeriodsPerPartTimeEmployees(partTimeEmployee);
            totalCost += myScheduleParameters.getFixedCostOfPartTimeEmployeesPerSchedule() + 
                    numberWorkingPeriod * myScheduleParameters.getWorkingPeriodCostOfPartTimeEmployeesPaidAtRegularHourlyRate();
        }
        for (int fullTimeEmployee = 0 ; fullTimeEmployee < myInitialSchedule.getNumberFullTimeEmployee() ; fullTimeEmployee++) {
            int numberWorkingPeriod = myInitialSchedule.getWorkingPeriodsPerFullTimeEmployees(fullTimeEmployee);
            totalCost += myScheduleParameters.getFixedCostOfFullTimeEmployeesPerSchedule() + 
                    numberWorkingPeriod * myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
        }
        return totalCost;
    }

    public static int getFullVariableDemandScheduleCost( VariableDemandSchedulesArray myVariableDemandSchedule, ParametersInitialSchedules myScheduleParameters) {
        int totalCost = 0;

        /* Coût spécifique à une augmentation de la demande */
        for(int p=0;p<myScheduleParameters.getWorkPeriodsPerSchedule();p++){
            totalCost += (myVariableDemandSchedule.getInitialSchedulesArrayVariableDemand().myParametersInitialSchedules.getRequiredWorkForce(p)-myScheduleParameters.getRequiredWorkForce(p))*
                    myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate()*1.5;
        }
        totalCost += getFullInitialScheduleCost(myVariableDemandSchedule.getInitialSchedulesArray(),myScheduleParameters);
        return totalCost;
    }
    
    public static int getFullAbsenceScheduleCost( AbsenceSchedulesArray myAbsenceSchedule, ParametersInitialSchedules myScheduleParameters) {
        int totalCost = 0;
        for (int partTimeEmployee = 0 ; partTimeEmployee < myAbsenceSchedule.getNumberPartTimeEmployee() ; partTimeEmployee++) {
            int numberWorkingPeriod = myAbsenceSchedule.getWorkingPeriodsPerPartTimeEmployees(partTimeEmployee);
            totalCost += myScheduleParameters.getFixedCostOfPartTimeEmployeesPerSchedule() + 
                    numberWorkingPeriod * myScheduleParameters.getWorkingPeriodCostOfPartTimeEmployeesPaidAtRegularHourlyRate();
        }
        for (int fullTimeEmployee = 0 ; fullTimeEmployee < myAbsenceSchedule.getNumberFullTimeEmployee() ; fullTimeEmployee++) {
            int numberWorkingPeriod = myAbsenceSchedule.getWorkingPeriodsPerFullTimeEmployees(fullTimeEmployee);
            int numberAbsencePeriod = myAbsenceSchedule.getAbsencePeriodsPerFullTimeEmployees(fullTimeEmployee);
            totalCost += myScheduleParameters.getFixedCostOfFullTimeEmployeesPerSchedule() + 
                    (numberWorkingPeriod + numberAbsencePeriod) * myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
        }
        return totalCost;
    }
    
    public static int getFullRecoveredScheduleCost( RecoveredSchedulesArray myRecoveredSchedule, ParametersInitialSchedules myScheduleParameters) {
        int totalCost = 0;
        for (int partTimeEmployee = 0 ; partTimeEmployee < myRecoveredSchedule.getNumberPartTimeEmployee() ; partTimeEmployee++) {
            int numberWorkingPeriod = myRecoveredSchedule.getWorkingPeriodsPerPartTimeEmployees(partTimeEmployee);
            totalCost += myScheduleParameters.getFixedCostOfPartTimeEmployeesPerSchedule() + 
                    numberWorkingPeriod * myScheduleParameters.getWorkingPeriodCostOfPartTimeEmployeesPaidAtRegularHourlyRate();
        }
        
        AbsenceSchedulesArray myAbsenceSchedule = myRecoveredSchedule.absenceSchedulesArray;
        for (int fullTimeEmployee = 0 ; fullTimeEmployee < myRecoveredSchedule.getNumberFullTimeEmployee() ; fullTimeEmployee++) {
            int numberWorkingPeriod = myRecoveredSchedule.getWorkingPeriodsPerFullTimeEmployees(fullTimeEmployee);
            int numberAbsencePeriod = myAbsenceSchedule.getAbsencePeriodsPerFullTimeEmployees(fullTimeEmployee);
            totalCost += myScheduleParameters.getFixedCostOfFullTimeEmployeesPerSchedule();
            int regularHourlyRateCost; int overtimeHourlyRateCost;
            if (numberWorkingPeriod + numberAbsencePeriod <= myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule() ) {
                regularHourlyRateCost = (numberWorkingPeriod + numberAbsencePeriod) * myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
                overtimeHourlyRateCost = 0;
            } else {
                regularHourlyRateCost =  myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule() * 
                                         myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
                overtimeHourlyRateCost = (numberWorkingPeriod + numberAbsencePeriod - myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule()) *
                                         myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtOvertimeHourlyRate();
            }
            totalCost += regularHourlyRateCost + overtimeHourlyRateCost;
        }
        return totalCost;
    }

    public static int getPartTimeEmployeeCost(boolean[][] currentEmployeesSchedule, int employee, ParametersInitialSchedules myScheduleParameters) {
        int numberWorkingPeriod = 0;
        for (int workPeriod = 0 ; workPeriod < currentEmployeesSchedule.length ; workPeriod++) {
            if (currentEmployeesSchedule[employee][workPeriod]) {
                numberWorkingPeriod++;
            }
        }
        return myScheduleParameters.getFixedCostOfPartTimeEmployeesPerSchedule() +
                numberWorkingPeriod * myScheduleParameters.getWorkingPeriodCostOfPartTimeEmployeesPaidAtRegularHourlyRate();
    }
    
    public static int getFullTimeEmployeeCost(boolean[][] currentEmployeesSchedule, AbsenceSchedulesArray myAbsenceSchedule, int employee, ParametersInitialSchedules myScheduleParameters) {
        int numberWorkingPeriod = 0;
        for (int workPeriod = 0 ; workPeriod < currentEmployeesSchedule.length ; workPeriod++) {
            if (currentEmployeesSchedule[employee][workPeriod]) {
                numberWorkingPeriod++;
            }
        }
        int numberAbsencePeriod = myAbsenceSchedule.getAbsencePeriodsPerFullTimeEmployees(employee);
        int regularHourlyRateCost; int overtimeHourlyRateCost;
        if (numberWorkingPeriod + numberAbsencePeriod <= myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule() ) {
            regularHourlyRateCost = (numberWorkingPeriod + numberAbsencePeriod) * myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
            overtimeHourlyRateCost = 0;
        } else {
            regularHourlyRateCost =  myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule() * 
                                     myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtRegularHourlyRate();
            overtimeHourlyRateCost = (numberWorkingPeriod + numberAbsencePeriod - myScheduleParameters.getWorkingPeriodsPaidAtRegularHourlyRatePerSchedule()) *
                                     myScheduleParameters.getWorkingPeriodCostOfFullTimeEmployeesPaidAtOvertimeHourlyRate();
        }
        return myScheduleParameters.getFixedCostOfFullTimeEmployeesPerSchedule() + regularHourlyRateCost + overtimeHourlyRateCost;
    }
}
