import { DetailsRadioOption } from '@common-ui/inputs/details-radio/details-radio-option';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper';
import { Dictionary, Dossier, File, IAddRedactionRequest, IEntityLogEntryPosition, IManualRedactionEntry } from '@red/domain';

export const EditRedactionOptions = {
    ONLY_HERE: 'ONLY_HERE',
    IN_DOCUMENT: 'IN_DOCUMENT',
} as const;

export type EditRedactionOption = keyof typeof EditRedactionOptions;

export const RedactOrHintOptions = {
    ONLY_HERE: 'ONLY_HERE',
    IN_DOCUMENT: 'IN_DOCUMENT',
    IN_DOSSIER: 'IN_DOSSIER',
} as const;

export type RedactOrHintOption = keyof typeof RedactOrHintOptions;

export const RectangleRedactOptions = {
    ONLY_THIS_PAGE: 'ONLY_THIS_PAGE',
    MULTIPLE_PAGES: 'MULTIPLE_PAGES',
} as const;

export type RectangleRedactOption = keyof typeof RectangleRedactOptions;

export const ForceAnnotationOptions = {
    ONLY_HERE: 'ONLY_HERE',
    IN_DOCUMENT: 'IN_DOCUMENT',
} as const;

export type ForceAnnotationOption = keyof typeof ForceAnnotationOptions;

export const ResizeOptions = RedactOrHintOptions;
export type ResizeRedactionOption = RedactOrHintOption;

export const RemoveRedactionOptions = {
    ONLY_HERE: 'ONLY_HERE',
    IN_DOCUMENT: 'IN_DOCUMENT',
    IN_DOSSIER: 'IN_DOSSIER',
    FALSE_POSITIVE: 'FALSE_POSITIVE',
    DO_NOT_RECOMMEND: 'DO_NOT_RECOMMEND',
} as const;
export const RemoveAnnotationOptions = RemoveRedactionOptions;

export type RemoveRedactionOption = keyof typeof RemoveRedactionOptions;
export type RemoveAnnotationOption = RemoveRedactionOption;

export interface LegalBasisOption {
    label?: string;
    legalBasis?: string;
    description?: string;
}

export interface RedactTextData {
    manualRedactionEntryWrapper: ManualRedactionEntryWrapper;
    dossierId: string;
    file: File;
    applyToAllDossiers?: boolean;
    isApprover?: boolean;
    isPageExcluded?: boolean;
}

export interface EditRedactionData {
    annotations: AnnotationWrapper[];
    allFileAnnotations?: AnnotationWrapper[];
    dossierId: string;
    file: File;
    isApprover?: boolean;
}

export type AddAnnotationData = RedactTextData;
export type AddHintData = RedactTextData;

export interface ForceAnnotationData {
    readonly dossier: Dossier;
    readonly annotations: AnnotationWrapper[];
    readonly hint: boolean;
    readonly image: boolean;
}

export interface ForceAnnotationResult {
    readonly annotationId?: string;
    readonly comment?: string;
    readonly legalBasis?: string;
    readonly reason?: string;
    readonly option?: ForceAnnotationOption;
}

export interface RedactTextResult {
    redaction: IManualRedactionEntry;
    dictionary: Dictionary;
    bulkLocal?: boolean;
}

export type RedactRecommendationData = EditRedactionData & {
    applyToAllDossiers: boolean;
};

export interface RedactRecommendationResult {
    redaction: IAddRedactionRequest;
    isMulti: boolean;
    bulkLocal: boolean;
}

export interface EditRedactResult {
    legalBasis: string;
    section: string;
    comment: string;
    type: string;
    value: string;
    option: EditRedactionOption | RectangleRedactOption;
    position: IEntityLogEntryPosition;
    pageNumbers?: number[];
}

export type AddHintResult = RedactTextResult;
export type AddAnnotationResult = RedactTextResult;

export interface ResizeRedactionPermissions {
    canResizeAnnotation: boolean;
    canResizeInDictionary: boolean;
}

export interface ResizeAnnotationData {
    redaction: AnnotationWrapper;
    text: string;
    dossierId: string;
}

export interface ResizeRedactionData extends ResizeAnnotationData {
    applyToAllDossiers?: boolean;
    isApprover?: boolean;
    permissions: ResizeRedactionPermissions;
}

export interface ResizeAnnotationResult {
    comment: string;
    updateDictionary: boolean;
    addToAllDossiers?: boolean;
}

export type ResizeRedactionResult = ResizeAnnotationResult;

export interface RemoveRedactionPermissions {
    canRemoveOnlyHere: boolean;
    canRemoveFromDictionary: boolean;
    canMarkAsFalsePositive: boolean;
}

export interface RemoveRedactionData {
    redactions: AnnotationWrapper[];
    allFileRedactions?: AnnotationWrapper[];
    dossier: Dossier;
    file?: File;
    falsePositiveContext: string[];
    permissions: RemoveRedactionPermissions;
    applyToAllDossiers: boolean;
    isApprover: boolean;
}

export type RemoveAnnotationData = RemoveRedactionData;

export interface RemoveRedactionResult {
    comment: string;
    option: DetailsRadioOption<RemoveRedactionOption>;
    applyToAllDossiers?: boolean;
    bulkLocal?: boolean;
    pageNumbers?: number[];
    position: IEntityLogEntryPosition;
}

export type RemoveAnnotationResult = RemoveRedactionResult;

export interface RectangleDialogData {
    dossierId: string;
    manualRedactionEntryWrapper: ManualRedactionEntryWrapper;
    file: File;
}
export interface RectangleDialogResult {
    annotation: IManualRedactionEntry;
}
