/*
 * 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 InitialSchedules;

import org.chocosolver.solver.constraints.extension.Tuples;

/**
 *
 * @author frabe
 */
class GenerationPossibleEmployeeSchedules {
    public static Tuples setWorkPeriodsSchedulesOfFullTimeEmployees(int shiftWorkPerDay, int workPeriodsPerSchedule, int workPeriodPerDay, int daysPerSchedule) {

        ValidDailySchedules validDailyFullTimeSchedules = new ValidDailySchedules(daysPerSchedule,
                10,
                10,
                5,
                7,
                12,
                4);

        int NbFullTimeSolutions = validDailyFullTimeSchedules.getNbSolutions();

        int[][] dailySchedulesOfFullTimeEmployees = validDailyFullTimeSchedules.getValidSchedules();

        int[][] workPeriodsSchedulesOfFullTimeEmployees
                = new int[NbFullTimeSolutions * shiftWorkPerDay][workPeriodsPerSchedule];

        // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite.
        for (int scheduleNumber = 0; scheduleNumber < NbFullTimeSolutions; scheduleNumber++) {
            for (int day = 0; day < daysPerSchedule; day++) {
                for (int shiftNumber = 0; shiftNumber < shiftWorkPerDay; shiftNumber++) {
                    if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 0) {
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay] = 1;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 1] = 1;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    } else if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 1) {
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 2] = 1;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 3] = 1;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    } else if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 2) {
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 4] = 1;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 5] = 1;
                    } else if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 0) {
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber * shiftWorkPerDay + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    }
                }
            }
        }

        // Creation des tuples a partir du tableau pour creer les 3 types de quart de travail (nuit, jour soir).
        return new Tuples(workPeriodsSchedulesOfFullTimeEmployees, true);
    }
    public static Tuples setWorkPeriodsSchedulesOfPartTimeEmployees(int workPeriodsPerSchedule, int workPeriodPerDay, int daysPerSchedule) {

        ValidDailySchedules validDailyPartTimeSchedules = new ValidDailySchedules(daysPerSchedule,
                4,
                8,
                0,
                0,
                0,
                6);

        int NbPartTimeSolutions = validDailyPartTimeSchedules.getNbSolutions();

        int[][] dailySchedulesOfPartTimeEmployees = validDailyPartTimeSchedules.getValidSchedules();

        int maxShiftConfig = 5;

        int[][] workPeriodsSchedulesOfPartTimeEmployees
                = new int[NbPartTimeSolutions * maxShiftConfig][workPeriodsPerSchedule];

        // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite.
        for (int scheduleNumber = 0; scheduleNumber < NbPartTimeSolutions; scheduleNumber++) {
            for (int day = 0; day < daysPerSchedule; day++) {
                for (int shiftNumber = 0; shiftNumber < maxShiftConfig; shiftNumber++) {
                    if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 0) {
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 1] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 1) {
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 1] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 2] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 2) {
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 2] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 3] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 3) {
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 3] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 4] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 4) {
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 4] = 1;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 5] = 1;
                    } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 0) {
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 1] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 2] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 3] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 4] = 0;
                        workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * workPeriodPerDay + 5] = 0;
                    }
                }
            }
        }

        // Creation des tuples a partir du tableau pour creer les 3 types de quart de travail (nuit, jour soir).
        return new Tuples(workPeriodsSchedulesOfPartTimeEmployees, true);
    }
}
