// 定义 CanExecuteHandler 类型
type CanExecuteHandler = (parameter: any) => boolean;
// 定义 ExecuteHandler 类型
type ExecuteHandler = (parameter: any) => void;

export class BaseCommand {
    private canExecuteHandler: CanExecuteHandler | null;
    private executeHandler: ExecuteHandler;

    constructor(executeHandler: ExecuteHandler, canExecuteHandler: CanExecuteHandler | null = null) {
        this.canExecuteHandler = canExecuteHandler;
        this.executeHandler = executeHandler;
    }

    public canExecute(parameter: any): boolean {
        return this.canExecuteHandler === null ? true : this.canExecuteHandler(parameter);
    }

    public execute(parameter: any): void {
        if (this.executeHandler) {
            this.executeHandler(parameter);
        }
    }
}