import { ActivityType as CwActivityType } from "../../generated/prisma/client";
import { Translation } from "./types";

type ApiTimeActivityTypeRecord = {
    id: number;
    description: string | null;
    minHours: number | null;
    maxHours: number | null;
    rate: number | null;
    costMultiplier: number;
    inactiveFlag: boolean;
    invoiceFlag: boolean;
    billableFlag: boolean;
    utilizationFlag: boolean;
    defaultFlag: boolean;
    multiplierFlag: boolean;
    createdById: string | null;
    updatedById: string | null;
    createdAt: Date;
    updatedAt: Date;
};

export const timeActivityTypeTranslation: Translation<
    CwActivityType,
    ApiTimeActivityTypeRecord
> = {
    values: [
        { from: "activityTypeRecId", to: "id" },
        { from: "description", to: "description" },
        {
            from: "hoursMin",
            to: "minHours",
            process: (value) => (value != null ? Number(value) : null),
        },
        {
            from: "hoursMax",
            to: "maxHours",
            process: (value) => (value != null ? Number(value) : null),
        },
        {
            from: "rate",
            to: "rate",
            process: (value) => (value != null ? Number(value) : null),
        },
        {
            from: "costMultiplier",
            to: "costMultiplier",
            process: (value) => (value != null ? Number(value) : 1),
        },
        {
            from: "inactiveFlag",
            to: "inactiveFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "invoiceFlag",
            to: "invoiceFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "billableFlag",
            to: "billableFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "utilizationFlag",
            to: "utilizationFlag",
            process: (value) => Boolean(value),
        },
        {
            from: "defaultFlag",
            to: "defaultFlag",
            process: (value) => Boolean(value ?? false),
        },
        {
            from: "multiplierFlag",
            to: "multiplierFlag",
            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),
        },
    ],
};
