import {BinaryTreeNode} from './binary-tree';
import {RBColor, RBTreeOptions} from '../types';
import {IRBTree, IRBTreeNode} from '../interfaces/rb-tree';
import {BST} from './bst';


export class RBTreeNode<T, FAMILY extends RBTreeNode<T, FAMILY>> extends BinaryTreeNode<T, FAMILY> implements IRBTreeNode<T, FAMILY> {
    // override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
    //     return val !== null ? new RBNode<T>(id, val, count) : null;
    // }

    constructor(id: number, val: T, count?: number) {
        super(id, val, count);
    }

    private _color: RBColor = RBColor.RED;

    get color(): RBColor {
        return this._color;
    }

    set color(value: RBColor) {
        this._color = value;
    }

    // private override _parent: RBNode<T> | null;
    // override set parent(v: RBNode<T> | null) {
    //     this._parent = v;
    // }
    // override get parent(): RBNode<T> | null {
    //     return this._parent;
    // }
    // private override _left?: RBNode<T> | null;
    //
    // override get left(): RBNode<T> | null | undefined {
    //     return this._left;
    // }
    //
    // override set left(v: RBNode<T> | null | undefined) {
    //     if (v) {
    //         v.parent = this;
    //         v.familyPosition = FamilyPosition.LEFT;
    //     }
    //     this._left = v;
    // }
    //
    // private override _right?: RBNode<T> | null;
    //
    // override get right(): RBNode<T> | null | undefined {
    //     return this._right;
    // }
    //
    // override set right(v: RBNode<T> | null | undefined) {
    //     if (v) {
    //         v.parent = this;
    //         v.familyPosition = FamilyPosition.RIGHT;
    //     }
    //     this._right = v;
    // }
}

export class RBTree<N extends RBTreeNode<N['val'], N>> extends BST<N> implements IRBTree<N> {
    constructor(options?: RBTreeOptions) {
        super(options);
    }

    // override createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
    //     return val !== null ? new RBNode<N>(id, val, count) : null;
    // }

    // private override _root: BinaryTreeNode<N> | null = null;
    //
    // override get root(): BinaryTreeNode<N> | null {
    //     return this._root;
    // }

    insert(id: number, val: N | null) {

    }

    private leftRotate(node: N) {

    }

    private rightRotate(node: N) {

    }

    private insertFixup(node: N) {

    }

    private deleteFixup(node: N) {

    }

    private transplant(u: N, v: N) {

    }

    // override remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<N>[] {
    //
    //     return [{deleted: new N(0, 0), needBalanced: null}];
    // }


}
