/*
 * 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 devrait etre ameliorer avec du polymorphisme car on dedouble le code pour les 2 types d'horaire.
        StringBuilder sbuf = new StringBuilder();
        sbuf.append(String.format("%-31s", "Schedule Day"));
        for (int day = 1; day <= schedule.myParametersInitialSchedules.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.getNumberPartTimeEmployee(); employee++) {
            sbuf.append(String.format("%s" + "%02d" + "%-20s","Employee ", employee + 1, " "));

            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.myParametersInitialSchedules.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.getNumberFullTimeEmployee(); employee++) {
            sbuf.append(String.format("%-5s" + "%02d" + "%-20s","Employee ", employee + 1, " "));

            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.myParametersInitialSchedules.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.getEmployeesWorkingPerWorkPeriod(workPeriod)));
            if (workPeriod % schedule.myParametersInitialSchedules.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.myParametersInitialSchedules.getRequiredWorkForce(workPeriod)));
            if (workPeriod % schedule.myParametersInitialSchedules.getWorkPeriodPerDay() == 5 && workPeriod != 0) {
                sbuf.append(String.format("%2s" + "%-2s", "" ,  "|"));
            }
        }
        sbuf.append("\n");
        sbuf.append(String.format("%s" + "%.2f" ,"Total schedule Cost : $", (double) schedule.totalScheduleCost));
        sbuf.append("\n");
        return sbuf.toString();
        
    }
    

}

