import { TeChargeCode as CwTeChargeCode } from "../../generated/prisma/client";
import { Translation } from "./types";

type ApiTimeEntryChargeCodeRecord = {
    id: number;
    chargeCodeId: number;
    description: string | null;
    expenseFlag: boolean;
    timeFlag: boolean;
    billableFlag: boolean;
    invoiceFlag: boolean;
    createdById: string | null;
    updatedById: string | null;
    createdAt: Date;
    updatedAt: Date;
};

export const timeEntryChargeCodeTranslation: Translation<
    CwTeChargeCode,
    ApiTimeEntryChargeCodeRecord
> = {
    values: [
        { from: "teChargeCodeRecId", to: "id" },
        { from: "teChargeCodeRecId", to: "chargeCodeId" },
        { from: "description", to: "description" },
        {
            from: "expenseFlag",
            to: "expenseFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "timeFlag",
            to: "timeFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "billableFlag",
            to: "billableFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "invoiceFlag",
            to: "invoiceFlag",
            process: (value) => Boolean(value ?? false),
        },
        { from: "enteredBy", to: "createdById" },
        { from: "updatedBy", to: "updatedById" },
        {
            from: "dateEnteredUtc",
            to: "createdAt",
            process: (value) => (value as Date | null) ?? new Date(0),
        },
        {
            from: "lastUpdateUtc",
            to: "updatedAt",
            process: (value) => (value as Date | null) ?? new Date(0),
        },
    ],
};
