/*
 * 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
 */
//Dans cette classe, toutes les fonctions sont dedoublees. On devrait faire du polymorphisme. 
public class SchedulesArray {
    public final int initialScheduleSolutionNumber;
    public boolean[][] partTimeSchedules;
    public boolean[][] fullTimeSchedules;
    public int totalScheduleCost;
    protected final ParametersInitialSchedules myParametersInitialSchedules;
 
    // Constructeur Copie
    protected SchedulesArray(SchedulesArray myScheduleArray) {
        
        this.myParametersInitialSchedules = myScheduleArray.myParametersInitialSchedules;
        this.partTimeSchedules = getDeepCopyEmployeesSchedules(myScheduleArray.partTimeSchedules);
        this.fullTimeSchedules = getDeepCopyEmployeesSchedules(myScheduleArray.fullTimeSchedules);
        this.initialScheduleSolutionNumber = myScheduleArray.initialScheduleSolutionNumber;
        this.totalScheduleCost = myScheduleArray.totalScheduleCost;
    }
    
    public SchedulesArray( FullTimeEmployeeScheduleArray fteisa, PartTimeEmployeeScheduleArray pteisa, int scheduleNumber){
        this.initialScheduleSolutionNumber = scheduleNumber;
        this.myParametersInitialSchedules = fteisa.myParametersInitialSchedules;
            
        this.partTimeSchedules = pteisa.partTimeSchedules;
        this.fullTimeSchedules = fteisa.fullTimeSchedules;
        
        this.totalScheduleCost = EmployeeCostCalculator.getFullInitialScheduleCost(this, myParametersInitialSchedules);
    }


    /**
     * This method creates a SchedulesArray with a modified required workforce vector
     *
     * @param myParametersInitialSchedules Parameters from initial schedule
     * @param fteisa                       initial schedules array for full time employees
     * @param pteisa                       initial schedules array for part time employees
     * @param scheduleNumber               Schedule number that comes from the initial Choco solution
     * @param VariableDemandVector         new required workforce vector
     */
    public SchedulesArray(ParametersInitialSchedules myParametersInitialSchedules, boolean[][] fteisa, boolean[][] pteisa, int scheduleNumber, int[] VariableDemandVector) {

        this.initialScheduleSolutionNumber = scheduleNumber;
        this.myParametersInitialSchedules = myParametersInitialSchedules;
        this.myParametersInitialSchedules.setRequiredWorkforce(VariableDemandVector);

        this.partTimeSchedules = getDeepCopyEmployeesSchedules(pteisa);
        this.fullTimeSchedules = getDeepCopyEmployeesSchedules(fteisa);
    }
    
    protected boolean[][] getDeepCopyEmployeesSchedules(boolean[][] schedules) {
        int nbrEmployee = schedules.length;
        int nbrWorkPeriod = schedules[0].length;
        boolean[][] copySchedules = new boolean[nbrEmployee][nbrWorkPeriod];
        for (int workPeriod = 0; workPeriod < nbrWorkPeriod; workPeriod++) {
            for (int employee = 0; employee < nbrEmployee; employee++) {
                copySchedules[employee][workPeriod] = schedules[employee][workPeriod];
            }
        }
        return copySchedules;
    }
    
    protected int getEmployeesWorkingPerWorkPeriod(int workPeriod) {
        int employeesWorking = 0;
        for (int employee = 0; employee < this.getNumberPartTimeEmployee(); employee++) {
            if (this.partTimeSchedules[employee][workPeriod]) {employeesWorking += 1;}
        }
        for (int employee = 0; employee < this.getNumberFullTimeEmployee(); employee++) {
            if (this.fullTimeSchedules[employee][workPeriod]) {
                employeesWorking += 1;
            }
        }
        return employeesWorking;
    }

    public int getWorkingPeriodsPerPartTimeEmployees(int employee) {
        int workingPeriodsPerPartTimeEmployees = 0;
        for (int workPeriod = 0; workPeriod < myParametersInitialSchedules.getWorkPeriodsPerSchedule(); workPeriod++) {
            if (this.partTimeSchedules[employee][workPeriod]) {workingPeriodsPerPartTimeEmployees += 1;}
        }
        return workingPeriodsPerPartTimeEmployees;
    }

    public int getWorkingPeriodsPerFullTimeEmployees(int employee) {
        int workingPeriodsPerFullTimeEmployees = 0;
        for (int workPeriod = 0; workPeriod < myParametersInitialSchedules.getWorkPeriodsPerSchedule(); workPeriod++) {
            if (this.fullTimeSchedules[employee][workPeriod]) {workingPeriodsPerFullTimeEmployees += 1;}
        }
        return workingPeriodsPerFullTimeEmployees;
    }
    
    public int getNumberFullTimeEmployee() {
        return this.fullTimeSchedules.length;
    }

    public int getNumberPartTimeEmployee() {
        return this.partTimeSchedules.length;
    }

    public int getWorkPeriodsPerSchedule() {
        return myParametersInitialSchedules.getWorkPeriodsPerSchedule();
    }
    
    public boolean isPartTimeEmployeeWorking(int employee, int workPeriod) {
        return partTimeSchedules[employee][workPeriod];
    }
    
    public boolean isFullTimeEmployeeWorking(int employee, int workPeriod) {
        return fullTimeSchedules[employee][workPeriod];
    }
    
}
