/** 
 * Utilities for working the data model. 
 */

import * as Model from "./DataModel"
import * as moment from "moment"
export * from "./time"

import { momentDateFormat, formatDate } from "./time"
         
export const formattedValuePostfix = "@OData.Community.Display.V1.FormattedValue"

/** Convert an attribute name to one with a OData formatted value. */
export function toFVName(name: string): string {
    return name + formattedValuePostfix
}

/** 
 * Copies object and adds DateStr attributse if corresponding Model.Audit attributes exist.
 */
export function enhanceAudit<T extends Model.Audit>(audit: T,
    format: string = momentDateFormat): T & Model.DateStr {
    const x = { ...(audit as any) }
    x.modifiedonstr = x.modifiedon ? formatDate(x.modifiedon) : null
    x.createdonstr = x.createdon ? formatDate(x.createdon) : null
    return x
}
