import {NestedTestableNodeData} from "../InMemoryTestableNode";
import {NestedBranchData, NestedTieredData} from "../MemoryBranchNode";
import {TreeNode} from "../TreeNode";
import {CloneTierAction} from "./interfaces";
import {TierType} from "../tiers";
import {removeFixedTestableValues} from "../testableHelpers";
import {TestablePartial} from "../store";

export class FixedValueTestableCloner implements CloneTierAction {
    canCloneTier(treeNode: TreeNode): boolean {
        return treeNode.getParentBranch()!.getExtraData().tierType === TierType.Fixed
    }

    cloneTier(nestedTestableNodeData: NestedTestableNodeData, nestedBranchData: NestedBranchData<NestedBranchData, NestedTieredData>, targetTreeNodeToClone: TreeNode) {
        // fixed values (eg: user roles, etc)
        // i think the current chosen way to go is to remove the values from the previous branch so that the select value popup is shown
        // after cloning the tier

        removeFixedTestableValues(
            nestedTestableNodeData as TestablePartial,
            targetTreeNodeToClone.getParentBranch()?.getBaseTestable()?.type!
        )
    }
}