import { IListable } from '@iqser/common-ui';
import { IAudit } from './audit';

export class Audit implements IAudit, IListable {
    readonly recordId: string;
    readonly category: string;
    readonly details?: { [key: string]: string };
    readonly message: string;
    readonly objectId?: string;
    readonly recordDate: string;
    readonly userId: string;
    readonly hasDetails: boolean;

    constructor(audit: IAudit) {
        this.category = audit.category;
        this.details = audit.details;
        this.message = audit.message;
        this.objectId = audit.objectId;
        this.recordDate = audit.recordDate;
        this.recordId = audit.recordId;
        this.userId = audit.userId;
        this.hasDetails = audit.details ? Object.keys(audit.details).length > 0 : false;
    }

    get id(): string {
        return this.recordId;
    }

    get searchKey(): string {
        return this.recordDate;
    }
}
