import { IListable } from '@iqser/common-ui';
import { List } from '@iqser/common-ui/lib/utils';
import { DownloadFileType } from '../shared';
import { DossierTemplateStatus, DossierTemplateStatuses } from './constants';
import { IDossierTemplate } from './dossier-template';

export class DossierTemplate implements IDossierTemplate, IListable {
    readonly createdBy: string;
    readonly dateAdded: string;
    readonly dateModified: string;
    readonly description?: string;
    readonly dossierTemplateId: string;
    readonly downloadFileTypes: List<DownloadFileType>;
    readonly modifiedBy?: string;
    readonly name: string;
    readonly reportTemplateIds?: List;
    readonly validFrom?: string;
    readonly validTo?: string;
    readonly dossierTemplateStatus: DossierTemplateStatus;
    readonly keepHiddenText: boolean;
    readonly keepImageMetadata: boolean;
    readonly keepOverlappingObjects: boolean;
    readonly applyDictionaryUpdatesToAllDossiersByDefault: boolean;
    readonly ocrByDefault: boolean;
    readonly removeWatermark: boolean;

    constructor(dossierTemplate: IDossierTemplate) {
        this.createdBy = dossierTemplate.createdBy;
        this.dateAdded = dossierTemplate.dateAdded;
        this.dateModified = dossierTemplate.dateModified;
        this.description = dossierTemplate.description;
        this.dossierTemplateId = dossierTemplate.dossierTemplateId;
        this.downloadFileTypes = dossierTemplate.downloadFileTypes;
        this.modifiedBy = dossierTemplate.modifiedBy;
        this.name = dossierTemplate.name;
        this.reportTemplateIds = dossierTemplate.reportTemplateIds;
        this.validFrom = dossierTemplate.validFrom;
        this.validTo = dossierTemplate.validTo;
        this.dossierTemplateStatus = dossierTemplate.dossierTemplateStatus;
        this.keepHiddenText = dossierTemplate.keepHiddenText;
        this.keepImageMetadata = dossierTemplate.keepImageMetadata;
        this.keepOverlappingObjects = dossierTemplate.keepOverlappingObjects;
        this.applyDictionaryUpdatesToAllDossiersByDefault = dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault;
        this.ocrByDefault = dossierTemplate.ocrByDefault;
        this.removeWatermark = dossierTemplate.removeWatermark;
    }

    get isActive(): boolean {
        return this.dossierTemplateStatus === DossierTemplateStatuses.ACTIVE;
    }

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

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

    get routerLink(): string {
        return `/main/admin/dossier-templates/${this.dossierTemplateId}`;
    }

    get dossiersRouterLink(): string {
        return `/main/${this.dossierTemplateId}/dossiers`;
    }
}
