/**
 * 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 { action, computed, makeObservable, observable } from 'mobx';
import { addUniqueEntry, hashArray } from '@finos/legend-shared';
import { QUERY_BUILDER_STATE_HASH_STRUCTURE } from '../../QueryBuilderStateHashUtils.js';
import { COLUMN_SORT_TYPE } from '../../../graph/QueryBuilderMetaModelConst.js';
export class SortColumnState {
    columnState;
    sortType = COLUMN_SORT_TYPE.ASC;
    constructor(columnState) {
        makeObservable(this, {
            columnState: observable,
            sortType: observable,
            setColumnState: action,
            setSortType: action,
            hashCode: computed,
        });
        this.columnState = columnState;
    }
    setColumnState(val) {
        this.columnState = val;
    }
    setSortType(val) {
        this.sortType = val;
    }
    get hashCode() {
        return hashArray([
            QUERY_BUILDER_STATE_HASH_STRUCTURE.SORT_COLUMN_STATE,
            this.sortType.toString(),
            this.columnState,
        ]);
    }
}
export class QueryResultSetModifierState {
    tdsState;
    showModal = false;
    limit;
    distinct = false;
    sortColumns = [];
    slice;
    constructor(tdsState) {
        makeObservable(this, {
            showModal: observable,
            limit: observable,
            distinct: observable,
            sortColumns: observable,
            slice: observable.ref,
            setShowModal: action,
            setLimit: action,
            setDistinct: action,
            setSortColumns: action,
            addSortColumn: action,
            updateSortColumns: action,
            setSlice: action,
            reset: action,
            hashCode: computed,
        });
        this.tdsState = tdsState;
    }
    setShowModal(val) {
        this.showModal = val;
    }
    setLimit(val) {
        this.limit = val === undefined || val <= 0 ? undefined : val;
    }
    setDistinct(val) {
        this.distinct = val;
    }
    setSortColumns(val) {
        this.sortColumns = val;
    }
    addSortColumn(val) {
        addUniqueEntry(this.sortColumns, val);
    }
    updateSortColumns() {
        this.sortColumns = this.sortColumns.filter((colState) => this.tdsState.tdsColumns.includes(colState.columnState));
    }
    setSlice(slice) {
        this.slice = slice;
    }
    reset() {
        this.sortColumns = [];
        this.distinct = false;
        this.limit = undefined;
    }
    get hashCode() {
        return hashArray([
            QUERY_BUILDER_STATE_HASH_STRUCTURE.RESULT_SET_MODIFIER_STATE,
            hashArray(this.sortColumns),
            this.limit?.toString() ?? '',
            this.distinct.toString(),
        ]);
    }
}
//# sourceMappingURL=QueryResultSetModifierState.js.map