import * as dayjs from 'dayjs';
import { getLeftDateTime } from '@iqser/common-ui/lib/utils';

export abstract class TrashItem {
    abstract readonly type: 'dossier' | 'file';
    abstract readonly ownerId?: string;
    abstract readonly ownerName: string;
    abstract readonly dossierId: string;
    abstract readonly fileDossierName: string;
    abstract readonly icon: string;
    readonly restoreDate: string;
    readonly canRestore: boolean;

    protected constructor(
        protected readonly _retentionHours: number,
        readonly softDeletedTime: string | undefined,
        readonly hasRestoreRights: boolean,
        readonly hasHardDeleteRights: boolean,
    ) {
        this.restoreDate = this.#restoreDate;
        this.canRestore = this.#canRestore;
    }

    abstract get id(): string;

    abstract get searchKey(): string;

    abstract get name(): string;

    get isDossier(): boolean {
        return this.type === 'dossier';
    }

    get isFile(): boolean {
        return this.type === 'file';
    }

    get #canRestore(): boolean {
        const { daysLeft, hoursLeft, minutesLeft } = getLeftDateTime(this.restoreDate);
        return daysLeft >= 0 || hoursLeft >= 0 || minutesLeft > 0;
    }

    get #restoreDate(): string {
        return dayjs(this.softDeletedTime).add(this._retentionHours, 'hours').toISOString();
    }
}
