import { BehaviorStatus } from "../BehaviorStatus.js";
import { AbstractDecoratorBehavior } from "./AbstractDecoratorBehavior.js";

/**
 *
 * @author Alex Goldring
 * @copyright Company Named Limited (c) 2026
 */
export class IgnoreFailureBehavior extends AbstractDecoratorBehavior {
    /**
     *
     * @param {Behavior} source
     * @return {IgnoreFailureBehavior}
     */
    static from(source) {
        const r = new IgnoreFailureBehavior();

        r.setSource(source);

        return r;
    }

    tick(timeDelta) {
        const behaviorStatus = this.__source.tick(timeDelta);

        if (behaviorStatus === BehaviorStatus.Failed) {
            return BehaviorStatus.Succeeded;
        }

        return behaviorStatus;
    }
}
