import { SoActivityNotes as CwSoActivityNotes } from "../../generated/prisma/client";
import { Translation, skipRow } from "./types";
import { TranslationContext } from "./context";

type ApiActivityNotesRecord = {
    id: number;
    notes: string;
    activityId: number | null;
    internalAnalysisFlag: boolean;
    enteredById: string | null;
    updatedById: string | null;
    createdAt: Date;
    updatedAt: Date;
};

export const activityNotesTranslation: Translation<
    CwSoActivityNotes,
    ApiActivityNotesRecord,
    TranslationContext
> = {
    values: [
        { from: "soActivityNotesRecId", to: "id" },
        {
            from: "notes",
            to: "notes",
            process: (value: string) => value,
        },
        {
            from: "soActivityRecId",
            to: "activityId",
            process: (value: number, context: TranslationContext) => {
                if (!context.activityIds.has(value)) {
                    skipRow(`Activity ${value} not found in API`);
                }
                return value;
            },
        },
        {
            from: "internalAnalysisFlag",
            to: "internalAnalysisFlag",
            process: (value) => Boolean(value),
        },
        { from: "enteredBy", to: "enteredById" },
        { from: "updatedBy", to: "updatedById" },
        { from: "dateCreatedUtc", to: "createdAt" },
        { from: "lastUpdateUtc", to: "updatedAt" },
    ],
};
