// 定义接口和类型
interface TreeViewNode {
    TradeName: string;
    MenuCode: string;
    Action: string;
    listLeaf: TreeViewLeaf[];
}

interface TreeViewLeaf {
    // 这里根据实际情况补充 TreeViewLeaf 的属性
}

interface LeafViewModel {
    new (leaf: TreeViewLeaf): LeafViewModel;
}

interface BaseCommand {
    new (action: (obj: any) => void): BaseCommand;
}

interface ObservableObject {
    RaisePropertyChanged(propertyName: string): void;
}

// NodeViewModel 类
export class NodeViewModel implements ObservableObject {
    public Node: TreeViewNode;
    public OpenTradeCommand: BaseCommand;
    private leafCollection: LeafViewModel[];

    public get LeafCollection(): LeafViewModel[] {
        return this.leafCollection;
    }

    public set LeafCollection(value: LeafViewModel[]) {
        this.leafCollection = value;
        this.RaisePropertyChanged('LeafCollection');
    }

    public get TradeName(): string {
        return this.Node.TradeName;
    }

    public set TradeName(value: string) {
        this.Node.TradeName = value;
        this.RaisePropertyChanged('TradeName');
    }

    public get MenuCode(): string {
        return this.Node.MenuCode;
    }

    public set MenuCode(value: string) {
        this.Node.MenuCode = value;
        this.RaisePropertyChanged('MenuCode');
    }

    public get DiscribleText(): string {
        if (this.Node.MenuCode && this.Node.MenuCode !== '') {
            return `${this.Node.MenuCode}--${this.Node.TradeName}`;
        }
        return this.Node.TradeName;
    }

    public get Action(): string {
        return this.Node.Action;
    }

    public set Action(value: string) {
        this.Node.Action = value;
        this.RaisePropertyChanged('Action');
    }

    private isChecked: boolean;

    public get IsChecked(): boolean {
        return this.isChecked;
    }

    public set IsChecked(value: boolean) {
        this.isChecked = value;
        this.RaisePropertyChanged('IsChecked');
    }

    constructor(node: TreeViewNode) {
        this.Node = node;
        this.IsChecked = false;
        this.leafCollection = [];
        this.OpenTradeCommand = new BaseCommand((obj) => this.OpenTradeAction(obj));

        try {
            const n = this.Node.listLeaf.length;
            for (let i = 0; i < n; i++) {
                const leaf = this.Node.listLeaf[i];
                this.LeafCollection.push(new LeafViewModel(leaf));
            }
        } catch (error) {
            return;
        }
    }

    public OpenTradeAction(obj: any): void {
        if (this.Action) {
            const actionId = this.Action;
        }
    }

    public RaisePropertyChanged(propertyName: string): void {
        // 这里可以实现属性变更通知的逻辑，例如触发事件
    }
}