package com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog;

import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;

import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.AnnotationStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.BaseAnnotation;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ManualChange {

    private AnnotationStatus annotationStatus;
    private ManualRedactionType manualRedactionType;
    private OffsetDateTime processedDate;
    private OffsetDateTime requestedDate;
    private String userId;
    private Map<String, String> propertyChanges = new HashMap<>();


    public static ManualChange from(BaseAnnotation baseAnnotation) {

        ManualChange manualChange = new ManualChange();
        manualChange.annotationStatus = baseAnnotation.getStatus();
        manualChange.processedDate = baseAnnotation.getProcessedDate();
        manualChange.requestedDate = baseAnnotation.getRequestDate();
        manualChange.userId = baseAnnotation.getUser();
        return manualChange;
    }


    public boolean isProcessed() {

        return processedDate != null;
    }


    public ManualChange withManualRedactionType(ManualRedactionType manualRedactionType) {

        this.manualRedactionType = manualRedactionType;
        return this;
    }


    public ManualChange withChange(String property, String value) {

        this.propertyChanges.put(property, value);
        return this;
    }

}
