export class PageVersionRecord {
    currentVersion: boolean;
    versionNum: number;
    versionUserId: string;
    versionMessage: string;
    versionUUID: string;
    versionCreateDate: Date;
    userDisplay: string;
}

export default class PageRecord {
    public UUID: string;
    public Name: string;
    public OrgUserId: string;
    public IsPublic = true;
    public IsVisibleInMenu = true;
    public ParentId: string;
    public NodeIds: Array<string>;
    public CreatedAt: Date;
    public UpdatedAt: Date;
    public CreatedUserId: string;
    public UpdateUserId: string;
    public ChildPageIds: Array<string>;
    public level: 'view'|'manage'|'update'|false;
    public PageType: 'page' | 'form' = 'page';
    public AdditionalData: any;

    constructor(data: any = {Name: 'Double-click to edit...'}) {
        [
            'UUID',
            'Name',
            'OrgUserId',
            'IsPublic',
            'IsVisibleInMenu',
            'ParentId',
            'NodeIds',
            'CreatedAt',
            'UpdatedAt',
            'CreatedUserId',
            'UpdateUserId',
            'ChildPageIds',
            'level',
            'PageType',
            'AdditionalData',
        ].forEach(field => {
            if ( field in data ) {
                this[field] = data[field];
            }
        });
    }

    toSave() {
        const data = {};
        [
            'UUID',
            'Name',
            'OrgUserId',
            'IsPublic',
            'IsVisibleInMenu',
            'ParentId',
            'NodeIds',
            'CreatedAt',
            'UpdatedAt',
            'CreatedUserId',
            'UpdateUserId',
            'ChildPageIds',
            'AdditionalData',
        ].forEach(field => {
            if ( field in this ) {
                data[field] = this[field];
            }
        });
        return data;
    }

    isViewOnly() {
        return this.level === 'view';
    }
}
