import {
  mapApiRgcDecisionsToRows,
  mapApiOpenIssuesToRows,
  mapApiAssignmentToDetail,
  type MinistryProgressReportDetail,
} from "@/features/ministry/progress-report/progress-report-detail-data";
import type { MinistryProgressReportIssueRow } from "@/features/ministry/progress-report/components/view-detail/progress-report-issues-data";
import type { DateLanguage } from "@/lib/date-utils";

import {
  getPswgAssignmentStatusLabel,
  type ApiPswgProgressReportDetail,
} from "./service/progress-report-service";

export function mapPswgProgressReportDetail(
  assignment: ApiPswgProgressReportDetail,
  language: DateLanguage = "en",
): MinistryProgressReportDetail {
  return {
    ...mapApiAssignmentToDetail(assignment, language),
    status: getPswgAssignmentStatusLabel(assignment.status),
  };
}

export function mapPswgIssuesToRows(
  assignment: ApiPswgProgressReportDetail,
): MinistryProgressReportIssueRow[] {
  return mapApiOpenIssuesToRows(assignment.openIssues);
}

export function mapPswgRgcDecisionsToRows(
  assignment: ApiPswgProgressReportDetail,
) {
  return mapApiRgcDecisionsToRows(
    assignment.rgcDecisions,
    assignment.ministry,
  );
}
