/*
 * Waltz - Enterprise Architecture
 * Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project
 * See README.md for more information
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.khartec.waltz.model;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.khartec.waltz.common.SetUtilities;
import com.khartec.waltz.model.application.ApplicationKind;
import org.immutables.value.Value;

import java.util.Set;

import static com.khartec.waltz.model.HierarchyQueryScope.CHILDREN;
import static com.khartec.waltz.model.HierarchyQueryScope.EXACT;


@Value.Immutable
@JsonSerialize(as = ImmutableIdSelectionOptions.class)
@JsonDeserialize(as = ImmutableIdSelectionOptions.class)
public abstract class IdSelectionOptions {

    public abstract EntityReference entityReference();
    public abstract HierarchyQueryScope scope();

    @Value.Default
    public Set<EntityLifecycleStatus> entityLifecycleStatuses() {
        return SetUtilities.fromArray(EntityLifecycleStatus.ACTIVE);
    }

    @Value.Default
    public SelectionFilters filters() {
        return ImmutableSelectionFilters.builder().build();
    }

    public static IdSelectionOptions mkOpts(EntityReference ref, HierarchyQueryScope scope) {
        return ImmutableIdSelectionOptions.builder()
                .entityReference(ref)
                .scope(scope)
                .build();
    }

    public static IdSelectionOptions mkOpts(EntityReference ref) {
        return ImmutableIdSelectionOptions.builder()
                .entityReference(ref)
                .scope(determineDefaultScope(ref.kind()))
                .build();
    }


    protected static HierarchyQueryScope determineDefaultScope(EntityKind kind) {
        switch (kind) {
            case ACTOR:
            case APPLICATION:
            case APP_GROUP:
            case CHANGE_INITIATIVE:
            case FLOW_DIAGRAM:
            case LOGICAL_DATA_ELEMENT:
            case LOGICAL_DATA_FLOW:
            case PHYSICAL_FLOW:
            case PHYSICAL_SPECIFICATION:
            case SCENARIO:
            case SERVER:
                return EXACT;
            default:
                return CHILDREN;
        }

    }


    public static void main(String[] args) {
        ImmutableIdSelectionOptions opts = ImmutableIdSelectionOptions
                .builder()
                .entityReference(EntityReference.mkRef(EntityKind.APPLICATION, 1L))
                .scope(EXACT)
                .filters(ImmutableSelectionFilters
                        .builder()
                        .addOmitApplicationKinds(ApplicationKind.IN_HOUSE)
                        .build())
                .build();
        System.out.println(opts);
    }
}

@@ -2890,533 +2890,13 @@
   %7D%0A
-%0A
     %7D%0A%0A
-%0A    public static void main(String%5B%5D args) %7B%0A        ImmutableIdSelectionOptions opts = ImmutableIdSelectionOptions%0A                .builder()%0A                .entityReference(EntityReference.mkRef(EntityKind.APPLICATION, 1L))%0A                .scope(EXACT)%0A                .filters(ImmutableSelectionFilters%0A                        .builder()%0A                        .addOmitApplicationKinds(ApplicationKind.IN_HOUSE)%0A                        .build())%0A                .build();%0A        System.out.println(opts);%0A    %7D%0A
 %7D%0A

Update IdSelectionOptions.java