export type Normalizer<T> = {
    [K in keyof T]: (_val: unknown) => T[K];
};

export const normalizeObject = <T>(raw: Partial<Record<keyof T, unknown>>, schema: Normalizer<T>): T => {
    const result = {} as T;
    for (const key in schema) {
        result[key] = schema[key](raw[key]);
    }
    return result;
}

// Example for Expense
// export interface Expense {
//     date: string;
//     type: "TRAVEL" | "MEAL" | "OTHER";
//     comment: string;
//     amount?: number;
//     mileage?: number;
// }

// const expenseNormalizer: Normalizer<Expense> = {
//     date: (v) => String(v ?? ""), // fallback to ""
//     type: (v) => (["TRAVEL", "MEAL", "OTHER"].includes(v) ? v : "OTHER"),
//     comment: (v) => String(v ?? ""),
//     amount: (v) => (typeof v === "number" ? v : undefined),
//     mileage: (v) => (typeof v === "number" ? v : undefined),
// };

// export const normalizeExpense = (raw: unknown): Expense =>
//     normalizeObject(raw, expenseNormalizer);