package com.capgemini.reports;

import com.capgemini.framework.common.SettingsHelper;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * Lists all existing reports, using the format REPORT_Rxy.
 */
@AllArgsConstructor
@Getter
public enum ReportEnum {
  REPORT_R01(null),
  REPORT_R03(null),
  REPORT_R05(null),
  REPORT_R06(null),
  REPORT_R07(null),
  REPORT_R10(null),
  REPORT_R11(null),
  REPORT_R13(null),
  REPORT_R15(null),
  REPORT_W15("autoR15real"),
  REPORT_R16(null),
  REPORT_R17(null),
  REPORT_R19(null),
  REPORT_R20(null),
  REPORT_R21(null),
  REPORT_R22(null),
  REPORT_W22("autoR22"),
  REPORT_R23(null),
  REPORT_R24(null),
  REPORT_R25(null),
  REPORT_R26(null),
  REPORT_R27(null),
  REPORT_R28(null);

  private final String urlForAutomaticGeneration;

  /**
   * Returns the corresponding report Code (i.e. 'RB1', or 'R07').
   *
   * @return the report code
   */
  public String getReportCode() {
    return toString().replace("REPORT_", "");
  }

  /**
   * Returns the report short name, in french.<br>
   * Exemple with the R01: 'Rapport R01'.
   *
   * @return the report code
   */
  public StringBuilder getReportName() {
    String reportCode = getReportCode();
    return new StringBuilder("Rapport ").append(reportCode.toUpperCase());
  }

  /**
   * Returns the official report title. <br>
   * Exemple for R01: 'BOM assemblage PU'.<br>
   * Title is extracted from the reporting.properties file.
   *
   * @return the report title
   */
  public String getReportTitle() {
    return SettingsHelper.getTitle(this);
  }

  /**
   * Returns the full report identifier and title.<br>
   * Exemple for R01: 'Rapport R01 "BOM assemblage PU"'
   *
   * @return the report identifier
   */
  public StringBuilder buildCompleteReportName() {
    return getReportName().append(" \"").append(getReportTitle()).append('"');
  }

  /**
   * Returns the {@link ReportEnum} of this report, if you provide its report Code.
   *
   * @param reportCode the report code, like 'R01' or 'RB1'
   * @return the matching {@link ReportEnum}
   */
  public static ReportEnum fromCode(final String reportCode) {
    return valueOf("REPORT_" + reportCode.toUpperCase());
  }

  /**
   * Returns the official list of report code.<br>
   * Exemple : Rxx
   *
   * @return list
   */
  public static List<String> getListReportCode() {
    List<String> allReportCode = new ArrayList<>();
    for (ReportEnum value : ReportEnum.values()) {
      allReportCode.add(value.getReportCode());
    }
    return allReportCode;
  }
}
