import type { StatusCount } from "@/components/ui/ItProgress.vue";
import type { CompetenceCertificateAssignment } from "@/types";
import _ from "lodash";

export function assignmentsMaxEvaluationPoints(
  assignments: CompetenceCertificateAssignment[]
): number {
  return _.sum(
    assignments
      .filter((a) => a.completion?.completion_status === "EVALUATION_SUBMITTED")
      .map((a) => a.max_points)
  );
}

export function assignmentsUserPoints(assignments: CompetenceCertificateAssignment[]) {
  return _.sum(
    assignments
      .filter((a) => a.completion?.completion_status === "EVALUATION_SUBMITTED")
      .map((a) => a.completion?.evaluation_points ?? 0)
  );
}

export function competenceCertificateProgressStatusCount(
  assignments: CompetenceCertificateAssignment[]
) {
  const numAssignmentsEvaluated = assignments.filter(
    (a) => a.completion?.completion_status === "EVALUATION_SUBMITTED"
  ).length;
  return {
    SUCCESS: numAssignmentsEvaluated,
    UNKNOWN: assignments.length - numAssignmentsEvaluated,
    FAIL: 0,
  } as StatusCount;
}
