/**
 * Copyright (c) 2020-present, Goldman Sachs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { QueryBuilderFilterOperator } from '../QueryBuilderFilterOperator.js';
import { PRIMITIVE_TYPE, } from '@finos/legend-graph';
import { hashArray, UnsupportedOperationError, } from '@finos/legend-shared';
import { buildFilterConditionState, buildFilterConditionExpression, } from './QueryBuilderFilterOperatorValueSpecificationBuilder.js';
import { buildNotExpression, getStandardPrimitiveTypeEquivalent, unwrapNotExpression, } from '../../QueryBuilderValueSpecificationHelper.js';
import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../../graph/QueryBuilderMetaModelConst.js';
import { QUERY_BUILDER_STATE_HASH_STRUCTURE } from '../../QueryBuilderStateHashUtils.js';
import { buildDefaultInstanceValue } from '../../shared/ValueSpecificationEditorHelper.js';
export class QueryBuilderFilterOperator_Contain extends QueryBuilderFilterOperator {
    getLabel() {
        return 'contains';
    }
    isCompatibleWithFilterConditionProperty(filterConditionState) {
        return (getStandardPrimitiveTypeEquivalent(filterConditionState.leftConditionType) === PRIMITIVE_TYPE.STRING);
    }
    isCompatibleWithFilterConditionValue(filterConditionState) {
        const type = filterConditionState.rightConditionValue &&
            !filterConditionState.rightConditionValue.isCollection
            ? filterConditionState.rightConditionValue.type
            : undefined;
        return (type !== undefined &&
            getStandardPrimitiveTypeEquivalent(type) === PRIMITIVE_TYPE.STRING);
    }
    getDefaultFilterConditionValue(filterConditionState) {
        const propertyType = filterConditionState.leftConditionType;
        switch (propertyType.path) {
            case PRIMITIVE_TYPE.STRING: {
                return buildDefaultInstanceValue(filterConditionState.filterState.queryBuilderState.graphManagerState
                    .graph, propertyType, filterConditionState.filterState.queryBuilderState.observerContext, filterConditionState.filterState.queryBuilderState
                    .INTERNAL__enableInitializingDefaultSimpleExpressionValue);
            }
            default:
                throw new UnsupportedOperationError(`Can't get default value for filter operator '${this.getLabel()}' when the LHS property is of type '${propertyType.path}'`);
        }
    }
    buildFilterConditionExpression(filterConditionState, lambdaParameterName) {
        return buildFilterConditionExpression(filterConditionState, QUERY_BUILDER_SUPPORTED_FUNCTIONS.CONTAINS, lambdaParameterName);
    }
    buildFilterConditionState(filterState, expression) {
        return buildFilterConditionState(filterState, expression, QUERY_BUILDER_SUPPORTED_FUNCTIONS.CONTAINS, this);
    }
    get hashCode() {
        return hashArray([
            QUERY_BUILDER_STATE_HASH_STRUCTURE.FILTER_OPERATOR_CONTAIN,
        ]);
    }
}
export class QueryBuilderFilterOperator_NotContain extends QueryBuilderFilterOperator_Contain {
    getLabel() {
        return `doesn't contain`;
    }
    buildFilterConditionExpression(filterConditionState, lambdaParameterName) {
        return buildNotExpression(super.buildFilterConditionExpression(filterConditionState, lambdaParameterName));
    }
    buildFilterConditionState(filterState, expression) {
        const innerExpression = unwrapNotExpression(expression);
        return innerExpression
            ? super.buildFilterConditionState(filterState, innerExpression)
            : undefined;
    }
    get hashCode() {
        return hashArray([
            QUERY_BUILDER_STATE_HASH_STRUCTURE.FILTER_OPERATOR_NOT_CONTAIN,
        ]);
    }
}
//# sourceMappingURL=QueryBuilderFilterOperator_Contain.js.map