"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListFilesCommand = void 0;
const yok_1 = require("../../yok");
class ListFilesCommand {
    constructor($devicesService, $stringParameter, $options, $projectData, $errors) {
        this.$devicesService = $devicesService;
        this.$stringParameter = $stringParameter;
        this.$options = $options;
        this.$projectData = $projectData;
        this.$errors = $errors;
        this.allowedParameters = [
            this.$stringParameter,
            this.$stringParameter,
        ];
    }
    async execute(args) {
        await this.$devicesService.initialize({
            deviceId: this.$options.device,
            skipInferPlatform: true,
        });
        const pathToList = args[0];
        let appIdentifier = args[1];
        if (!appIdentifier) {
            try {
                this.$projectData.initializeProjectData();
            }
            catch (err) {
            }
            if (!this.$projectData.projectIdentifiers) {
                this.$errors.fail("Please enter application identifier or execute this command in project.");
            }
        }
        const action = async (device) => {
            appIdentifier =
                appIdentifier ||
                    this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
            await device.fileSystem.listFiles(pathToList, appIdentifier);
        };
        await this.$devicesService.execute(action);
    }
}
exports.ListFilesCommand = ListFilesCommand;
yok_1.injector.registerCommand(["device|list-files", "devices|list-files"], ListFilesCommand);
