import { ExperienceType } from "@/type/profileType";
import {
  ExperienceFormValues,
  MappedExperience,
} from "../types/experience.types";

export function mapFormToBody(exp: ExperienceFormValues): ExperienceType {
  return {
    job_title: exp.designation,
    company_name: exp.companyName,
    company_url: exp.companyWebsiteLink || "",
    employment_type: exp.jobType?.value || "",
    start_date: exp.startDate ? new Date(exp.startDate).toISOString() : null,
    end_date: exp.currentJob
      ? null
      : exp.endDate
        ? new Date(exp.endDate).toISOString()
        : undefined,
    is_current: exp.currentJob,
    responsibilities: exp.jobRes || "",
  };
}

export function mapItemToFormValues(
  item: MappedExperience,
): ExperienceFormValues {
  return {
    designation: item.label,
    jobType: item.type ? { label: item.type, value: item.type } : null,
    companyName: item.company,
    companyWebsiteLink: "",
    startDate: item.start_date ? new Date(item.start_date) : "",
    endDate: item.end_date ? new Date(item.end_date) : "",
    currentJob: !item.end_date,
    jobRes: item.responsibilities,
  };
}
