import {BranchNode} from "./StateBranchNode";
import {Offers} from "./Offers";
import {Grove, TreeNodeData} from "./Grove";


export class BranchChildrenFactory {
    constructor(
        private readonly offers: Offers,
        private readonly grove: Grove
    ) {
    }

    get: Parameters<BranchNode['getChildren']>[0] = (child, branch)  => {
        if (branch.isOffers()) {
            return this.offers.get(child as string);
        } else if (branch.isTiered()) {
            return this.grove.get((child as TreeNodeData).id);
        }
    }
}