/*-
 * ~~~~~~licensing~~~~~~
 * atlasmap-entaxy-libs
 * ==========
 * Copyright (C) 2020 - 2025 EmDev LLC
 * ==========
 * You may not use this file except in accordance with the License Terms of the Copyright
 * Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
 * rights to the Software and any copies are the property of the Copyright Holder. Unless
 * it is explicitly allowed the Copyright Holder, the User is prohibited from using the
 * Software for commercial purposes to provide services to third parties.
 * 
 * The Copyright Holder hereby declares that the Software is provided on an "AS IS".
 * Under no circumstances does the Copyright Holder guarantee or promise that the
 * Software provided by him will be suitable or not suitable for the specific purposes
 * of the User, that the Software will meet all commercial and personal subjective
 * expectations of the User, that the Software will work properly, without technical
 * errors, quickly and uninterruptedly.
 * 
 * Under no circumstances shall the Copyright Holder or its Affiliates is not liable
 * to the User for any direct or indirect losses of the User, his expenses or actual
 * damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
 * or damage to data, property, etc.
 * ~~~~~~/licensing~~~~~~
 */
package io.atlasmap.v2.entaxy;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonTypeName;

import io.atlasmap.entaxy.DataMapperLookup;
import io.atlasmap.spi.entaxy.EntaxyAction;
import io.atlasmap.spi.entaxy.LookupValues;
import io.atlasmap.v2.Action;
import io.atlasmap.v2.AtlasActionProperty;
import io.atlasmap.v2.FieldType;

@JsonTypeName(value = "Entaxy :: Map Data")
@EntaxyAction(actionId = "Entaxy :: Map Data")
public class MapData extends Action implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum NO_DATA_ACTION {
        USE_ORIGIN,
        RETURN_NULL,
        RETURN_VALUE,
        THROW_EXCEPTION
    }

    public enum RETURN_TYPE {
        STRING,
        BOOLEAN,
        LONG,
        DOUBLE
    }

    protected String mapToUse;

    protected NO_DATA_ACTION noDataAction = NO_DATA_ACTION.USE_ORIGIN;

    protected String noDataValue;

    protected boolean disableTrimWhitespace;

    protected RETURN_TYPE returnType = RETURN_TYPE.STRING;

    public String getMapToUse() {
        return mapToUse;
    }

    @JsonPropertyDescription("The map used for mapping")
    @AtlasActionProperty(title = "Map", type = FieldType.STRING)
    public void setMapToUse(@LookupValues(lookupClass = DataMapperLookup.class) String mapToUse) {
        this.mapToUse = mapToUse;
    }

    public NO_DATA_ACTION getNoDataAction() {
        return noDataAction;
    }

    @JsonPropertyDescription("What to do if no data or mapping fails")
    @AtlasActionProperty(title = "No data action", type = FieldType.STRING)
    public void setNoDataAction(NO_DATA_ACTION noDataAction) {
        this.noDataAction = noDataAction;
    }

    public RETURN_TYPE getReturnType() {
        return returnType;
    }

    @JsonPropertyDescription("Return type")
    @AtlasActionProperty(title = "Return type", type = FieldType.STRING)
    public void setReturnType(RETURN_TYPE returnType) {
        this.returnType = returnType;
    }

    public String getNoDataValue() {
        return noDataValue;
    }

    @JsonPropertyDescription("Value to return when no data got from mapping")
    @AtlasActionProperty(title = "No data value", type = FieldType.STRING)
    public void setNoDataValue(String noDataValue) {
        this.noDataValue = noDataValue;
    }

    public boolean isDisableTrimWhitespace() {
        return disableTrimWhitespace;
    }


    @JsonPropertyDescription("Needs to remove whitespace characters from the beginning and end of the line if source is string")
    @AtlasActionProperty(title = "Disable trim", type = FieldType.BOOLEAN)
    public void setDisableTrimWhitespace(boolean disableTrimWhitespace) {
        this.disableTrimWhitespace = disableTrimWhitespace;
    }
}
