"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetOrientationExecutor = void 0;
const execution_1 = require("@mablhq-internal/runtime/execution");
const execution_2 = require("@mablhq-internal/runtime/execution");
class SetOrientationExecutor {
    run(step, executionContext) {
        return (0, execution_1.runActionWithElementReadyRetriesForMobile)(() => this.setOrientation(step, executionContext), executionContext);
    }
    async setOrientation(step, executionContext) {
        const { mobileTestEnvironment } = executionContext;
        const currentOrientation = await mobileTestEnvironment.getOrientation();
        if (currentOrientation === step.orientation) {
            return { status: execution_2.StepStatus.Skipped };
        }
        await executionContext.observeDeferredFunction();
        try {
            await mobileTestEnvironment.setOrientation(step.orientation);
            return { status: execution_2.StepStatus.Passed };
        }
        catch (error) {
            executionContext.log.error(`Failed to set device orientation: ${error}`);
            return {
                status: execution_2.StepStatus.Failed,
                logInfo: 'Unable to set the orientation',
            };
        }
    }
}
exports.SetOrientationExecutor = SetOrientationExecutor;
