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


/**
 *
 * @author frabe
 */

// classe statique pour mettre fonction utilitaire
public class PrintSchedules {
    
    public static String getFormattedSchedule(SchedulesArray schedule) {
        // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite.
        StringBuilder sbuf = new StringBuilder();
        sbuf.append(String.format("%-31s", "Schedule Day"));
        for (int day = 1; day <= schedule.getDaysPerSchedule(); day++) {
            sbuf.append(String.format("%02d" + "%18s" + "%s", day, "" , "|"));
        }
        sbuf.append(" Worked Periods\n");
        
        sbuf.append("Part-Time Employees\n");   
        for (int employee = 0; employee < schedule.getMaxPartTimeEmployee(); employee++) {
            sbuf.append(String.format("%s" + "%02d" + "%-20s","Employee ", employee, " "));

            for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) {
                if (schedule.isPartTimeEmployeeWorking(employee,workPeriod)) {
                    sbuf.append(String.format("%2d", 1));
                } else {
                    sbuf.append(String.format("%2d", 0));
                }
                if (workPeriod % schedule.getWorkPeriodPerDay()== 5 && workPeriod != 0) {
                    sbuf.append(String.format("%2s" + "%-2s", "" ,  "|"));
                }
            }
            
            sbuf.append(String.format("%02d" + "%s", schedule.getWorkingPeriodsPerPartTimeEmployees(employee), "\n"));
        }
        
        sbuf.append("Full-Time Employees\n");   
        for (int employee = 0; employee < schedule.getMaxFullTimeEmployee(); employee++) {
            sbuf.append(String.format("%-5s" + "%02d" + "%-20s","Employee ", employee, " "));

            for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) {
                if (schedule.isFullTimeEmployeeWorking(employee,workPeriod)) {
                    sbuf.append(String.format("%2d", 1));
                } else {
                    sbuf.append(String.format("%2d", 0));
                }
                if (workPeriod % schedule.getWorkPeriodPerDay()== 5 && workPeriod != 0) {
                    sbuf.append(String.format("%2s" + "%-2s", "" ,  "|"));
                }
            }
            sbuf.append(String.format("%02d" + "%s", schedule.getWorkingPeriodsPerFullTimeEmployees(employee), "\n"));

        }
        
        sbuf.append(String.format("%-24s", "Working Employees "));
        for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) {
            sbuf.append(String.format("%2d", schedule.getEmployeesPerWorkPeriod(workPeriod)));
            if (workPeriod % schedule.getWorkPeriodPerDay() == 5 && workPeriod != 0) {
                sbuf.append(String.format("%2s" + "%-2s", "" ,  "|"));
            }
        }
        sbuf.append("\n");
        
        sbuf.append(String.format("%-25s", "Required Workforce "));
        for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) {
            sbuf.append(String.format("%2d", schedule.getRequiredWorkForce(workPeriod)));
            if (workPeriod % schedule.getWorkPeriodPerDay() == 5 && workPeriod != 0) {
                sbuf.append(String.format("%2s" + "%-2s", "" ,  "|"));
            }
        }
        sbuf.append("\n");
        
        return sbuf.toString();
        
    }
    

}

