package gov.cms.grouper.snf.component.r2.logic.nursing;

import gov.cms.grouper.snf.lego.SnfUtils;
import gov.cms.grouper.snf.lego.TriFunction;
import gov.cms.grouper.snf.model.AssessmentType;
import gov.cms.grouper.snf.model.reader.Rai300;
import gov.cms.grouper.snf.util.ClaimInfo;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Const {
  public static final int functionScoreLimit = 11;
  public static final int nursingCountNumDaysInLast7Days = 6;

  // To calculate function scores
  public static final Map<Boolean, Set<Rai300>> eatToilet = SnfUtils
      .concat(Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_EATING),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_EATING_IPA),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_HYGIENE_TOILET),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_HYGIENE_TOILET_IPA))
      .stream()
      .collect(Collectors.groupingBy((rai) -> rai.getAssessmentType().name().endsWith("IPA"),
          Collectors.mapping((rai) -> rai, Collectors.toSet())));

  public static final Map<Boolean, Set<Rai300>> bedMobility = SnfUtils
      .concat(Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_BED_MOBILITY_TO_LYING),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_BED_MOBILITY_TO_LYING_IPA),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_BED_MOBILITY_TO_SITTING),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_BED_MOBILITY_TO_SITTING_IPA))
      .stream()
      .collect(Collectors.groupingBy((rai) -> rai.getAssessmentType().name().endsWith("IPA"),
          Collectors.mapping((rai) -> rai, Collectors.toSet())));

  public static final Map<Boolean, Set<Rai300>> transfer = SnfUtils
      .concat(Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_TRANSFER_CHAIR),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_TRANSFER_CHAIR_IPA),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_TRANSFER_TO_STANDING),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_TRANSFER_TO_STANDING_IPA),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_TRANSFER_TOILET),
          Rai300.getAssessmentsByType(AssessmentType.FUNCTIONAL_TRANSFER_TOILET_IPA))
      .stream()
      .collect(Collectors.groupingBy((rai) -> rai.getAssessmentType().name().endsWith("IPA"),
          Collectors.mapping((rai) -> rai, Collectors.toSet())));

  public static final Function<ClaimInfo, Function<Rai300, Integer>> assessmentValue =
      (claim) -> (rai300) -> claim.getAssessmentValue(rai300);

  public static final TriFunction<Integer, ClaimInfo, String, Integer> assessmentValueFunction =
      (version, claim, raiString) -> claim
          .performanceRecode(() -> claim.getAssessmentValue(Rai300.valueOf(raiString)));

}
