import { AnnotationPermissions } from '@models/file/annotation.permissions';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { Dictionary } from '@red/domain';

export const canUndo = (annotation: AnnotationWrapper, isApprover: boolean) =>
    !isApprover && (annotation.isSuggestion || annotation.pending);

export const canForceHint = (annotation: AnnotationWrapper, canAddRedaction: boolean) =>
    canAddRedaction && annotation.isIgnoredHint && !annotation.pending;

export const canForceRedaction = (annotation: AnnotationWrapper, canAddRedaction: boolean) =>
    canAddRedaction && annotation.isSkipped && !annotation.isFalsePositive && !annotation.pending;

export const canAcceptRecommendation = (annotation: AnnotationWrapper) => annotation.isRecommendation && !annotation.pending;

export const canMarkAsFalsePositive = (annotation: AnnotationWrapper, annotationEntity: Dictionary) =>
    annotation.canBeMarkedAsFalsePositive && annotationEntity.hasDictionary;

export const canRemoveOnlyHere = (annotation: AnnotationWrapper, canAddRedaction: boolean) =>
    canAddRedaction && !annotation.pending && (annotation.isRedacted || (annotation.isHint && !annotation.isImage));

export const canRemoveFromDictionary = (annotation: AnnotationWrapper) =>
    annotation.isModifyDictionary &&
    (annotation.isRedacted || annotation.isSkipped || annotation.isHint) &&
    !annotation.pending &&
    !annotation.hasBeenResized;

export const canRemoveRedaction = (annotation: AnnotationWrapper, permissions: AnnotationPermissions) =>
    !annotation.isIgnoredHint &&
    (permissions.canRemoveOnlyHere || permissions.canRemoveFromDictionary || permissions.canMarkAsFalsePositive);

export const canChangeLegalBasis = (annotation: AnnotationWrapper, canAddRedaction: boolean) =>
    canAddRedaction && annotation.isRedacted && !annotation.pending;

export const canRecategorizeAnnotation = (annotation: AnnotationWrapper, canRecategorize: boolean) =>
    canRecategorize &&
    ((annotation.isImage && !annotation.isSuggestion) || annotation.isSuggestionRecategorizeImage || annotation.hintDictionary) &&
    !annotation.pending;

export const canResizeAnnotation = (annotation: AnnotationWrapper, canAddRedaction: boolean) =>
    canAddRedaction &&
    !annotation.isSkipped &&
    !annotation.pending &&
    (((annotation.isRedacted || annotation.isImage) && !annotation.isSuggestion) ||
        annotation.isSuggestionResize ||
        annotation.isDictBasedHint ||
        annotation.isRecommendation);
