package com.friday.tooldriver.dto.uipath.common;

import com.friday.tooldriver.constants.uipath.FilterOperation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class FilterEntity implements Serializable {
    private Entity left;
    private FilterOperation operations;
    private Entity right;
    private String value;

    @Override
    public String toString() {
        if (StringUtils.isEmpty(value)) {
            value = left.getValueString() + " " + this.operations.getOperator() + " " + right.getValueString();
        }
        return value;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Entity {
        private FilterEntity valueEntity;
        private String valueString;
        private boolean group;

        String getValueString() {
            if (StringUtils.isEmpty(this.valueString)) {
                this.valueString = valueEntity.toString();
            }
            if (group) {
                valueString = "(" + valueString + ")";
            }
            return valueString;
        }
    }
}