import { ActivityClass as CwActivityClass } from "../../generated/prisma/client";
import { Translation } from "./types";

type ApiTimeActivityClassRecord = {
    id: number;
    description: string | null;
    hourlyRate: number | null;
    inactiveFlag: boolean;
    taxExemptFlag: boolean;
    createdById: string | null;
    updatedById: string | null;
    createdAt: Date;
    updatedAt: Date;
};

export const timeActivityClassTranslation: Translation<
    CwActivityClass,
    ApiTimeActivityClassRecord
> = {
    values: [
        { from: "activityClassRecId", to: "id" },
        { from: "description", to: "description" },
        {
            from: "hourlyRate",
            to: "hourlyRate",
            process: (value) => (value != null ? Number(value) : null),
        },
        {
            from: "inactiveFlag",
            to: "inactiveFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "taxExemptFlag",
            to: "taxExemptFlag",
            process: (value) => Boolean(value),
        },
        { from: "enteredBy", to: "createdById" },
        { from: "updatedBy", to: "updatedById" },
        {
            from: "dateEnteredUtc",
            to: "createdAt",
            process: (value) => (value as Date | null) ?? new Date(0),
        },
        {
            from: "lastUpdatedUtc",
            to: "updatedAt",
            process: (value) => (value as Date | null) ?? new Date(0),
        },
    ],
};
