package com.aps.entity.common;

import java.util.List;
import java.util.stream.Collectors;

public class ConditionEntity {

    private String fieldName;
    private String fieldValue;
    private String conditionalType;


    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldValue() {
        return fieldValue;
    }
    public String getSafeValue() {
        String safe=fieldValue.replaceAll("(?i)(delete|drop|\\s|%|;|or|‘)","");
        return safe;
    }
    public void setFieldValue(Object fieldValue) {
        if (fieldValue == null) {
            this.fieldValue = null;
        } else if (fieldValue instanceof List) {
            this.fieldValue = ((List<?>) fieldValue).stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining(","));
        } else {
            this.fieldValue = String.valueOf(fieldValue);
        }
    }

    public String getConditionalType() {
        return conditionalType;
    }

    public void setConditionalType(String conditionalType) {
        this.conditionalType = conditionalType;
    }

    @Override
    public String toString() {
        return "ConditionEntity{" +
                "fieldName='" + fieldName + '\'' +
                ", fieldValue='" + fieldValue + '\'' +
                ", conditionalType='" + conditionalType + '\'' +
                '}';
    }
}
