import { CampaignDto, CampaignUpsertDto } from "types/campaigns";
import { CampaignFormDto } from "./types";

export function toFormDto(values: CampaignDto): CampaignFormDto {
  return {
    name: values.name,
    subject: values.subject,
    segmentIds: values.segments.map((o) => o.segmentId),
    templateId: values.template?.templateId ?? null,
    schedule: {
      sendType: values.schedule.sendType,
      endTimestamp: values.schedule.endTimestamp,
      startTimestamp: values.schedule.startTimestamp,
      timezone: values.schedule.timezone,
    },
  };
}
export function toUpsertDto(values: CampaignFormDto): CampaignUpsertDto {
  return {
    name: values.name,
    subject: values.subject,
    segmentIds: values.segmentIds,
    templateId: values.templateId,
    schedule: {
      sendType: values.schedule.sendType,
      endTimestamp: values.schedule.endTimestamp,
      startTimestamp: values.schedule.startTimestamp,
      timezone: values.schedule.timezone,
    },
  };
}
