import { TreeNode } from "../TreeNode";
import {CloneTierAction} from "./interfaces";
import {NestedTestableNodeData} from "../InMemoryTestableNode";
import {NestedBranchData} from "../MemoryBranchNode";
import {OfferData} from "../store";
import {TieredExtraData} from "../StateBranchNode";
import {generateDefaultNestedSelectActionsBranchData} from "../NodeHelpers";

export class TieredBranchCloner implements CloneTierAction {
    canCloneTier(treeNode: TreeNode): boolean {
        return treeNode.branchNode.isTiered()
    }

    // @ts-ignore
    cloneTier(nestedTestableNodeData: NestedTestableNodeData, nestedBranchData: NestedBranchData<OfferData, TieredExtraData>) {
        // FOR NOW, just remove the children and change the branch to a default select actions,
        // we don't want to clone the whole tree node for now, maybe in a later version as
        // a nice update but this is too complex for now
        const defaultSelectActions = generateDefaultNestedSelectActionsBranchData()

        nestedBranchData.type = defaultSelectActions.type
        // @ts-ignore
        nestedBranchData.data = defaultSelectActions.data
        nestedBranchData.children = defaultSelectActions.children
    }
}