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.entitymapped.BaseAnnotation;

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

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

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


    public static ManualChange from(BaseAnnotation baseAnnotation, int processedAnalysisNumber) {

        ManualChange manualChange = new ManualChange();
        manualChange.processedDate = baseAnnotation.getProcessedDate();
        manualChange.requestedDate = baseAnnotation.getRequestDate();
        manualChange.userId = baseAnnotation.getUser();
        manualChange.processedAnalysisNumber = processedAnalysisNumber;
        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) {

        if (value == null) {
            return this;
        }
        this.propertyChanges.put(property, value);
        return this;
    }

}
