import { Activity } from './activity.model';
import { GemensamPlaneringPostRequest } from './api/gemensam-planering.request.model';
import { GemensamPlaneringResponse } from './api/gemensam-planering.response.model';

export interface GemensamPlanering {
  genomforandeReferens: number;
  distance: boolean;
  activityIds: number[];
}

export interface GemensamPlaneringDetailed {
  genomforandeReferens: number;
  distance: boolean;
  activities: string[];
  status?: string;
  motivation?: string;
}

export function mapGemensamPlaneringToGemensamPlaneringPostRequest(
  gemensamPlanering: GemensamPlanering
): GemensamPlaneringPostRequest {
  const { genomforandeReferens, distance, activityIds } = gemensamPlanering;

  return {
    genomforandeReferens,
    distans: distance,
    aktivitetsIds: activityIds,
  };
}

export function mapResponseToGemensamPlaneringDetailed(
  data: GemensamPlaneringResponse,
  activities: Activity[]
): GemensamPlaneringDetailed {
  const { genomforandeReferens, distans, aktivitetsIds, status, motivation } = data;

  return {
    genomforandeReferens: +genomforandeReferens,
    distance: distans,
    activities: aktivitetsIds.map(id => activities.find(activity => activity.id === id).name),
    status,
    motivation,
  };
}
