import { Activity } from './activity.model';
import { PeriodiskRedovisningResponse } from './api/periodisk-redovisning.response.model';

export interface PeriodiskRedovisningActivity {
  id: number;
  name: string;
  performedRemotely: boolean;
  performedPhysically: boolean;
  hours: number;
}

export interface PeriodiskRedovisning {
  genomforandeReferens: number;
  period: string;
  hasOfferedLanguageSupport: boolean;
  hasOfferedJob: boolean;
  activities: PeriodiskRedovisningActivity[];
  motivation?: string;
  status?: string;
}

export function mapResponseToPeriodiskRedovisning(
  data: PeriodiskRedovisningResponse,
  allActivities: Activity[]
): PeriodiskRedovisning {
  const { genomforandeReferens, period, hasOfferedLanguageSupport, hasOfferedJob, activities } = data.content;

  return {
    genomforandeReferens,
    period,
    hasOfferedJob,
    hasOfferedLanguageSupport,
    activities: activities.map(({ id, performedRemotely, performedPhysically, hours }) => ({
      id,
      name: allActivities.find(activity => activity.id === id).name,
      performedRemotely,
      performedPhysically,
      hours,
    })),
    motivation: data.motivation,
    status: data.status,
  };
}
