"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const utils_1 = require("../../core/libs/utils/utils");
const help_1 = __importDefault(require("../extends/command/help"));
const enum_1 = require("../utils/enum");
const upload_1 = __importDefault(require("../implements/upload"));
const fg_1 = require("../utils/fg");
class Upload extends help_1.default {
    async run() {
        const { args, flags } = this.parse(Upload);
        const upload = new upload_1.default();
        upload.eventTracker('upload_start', { tags: Object.assign(Object.assign({}, args), flags) });
        const enableBlock = (0, fg_1.featureGatingBlock)();
        args.path = (0, utils_1.resolvePath)(args.path);
        if (!flags.type) {
            flags.type = await upload.detectAppType(args.path);
        }
        if (flags.type === enum_1.TypeEnum.Gadget) {
            await upload.gadget({
                path: args.path,
                platform: flags.platform,
                version: flags.version,
                description: flags.description,
                useNPM: flags.useNPM,
            });
        }
        else if (flags.type === enum_1.TypeEnum.Block) {
            if (enableBlock) {
                await upload.block({
                    path: args.path,
                    version: flags.version,
                    description: flags.description,
                });
            }
            else {
                this.error('This feature will be available soon');
            }
        }
    }
}
exports.default = Upload;
Upload.aliases = ['up'];
Upload.description = 'Upload project to feishu Open Platform';
Upload.examples = [
    ['$ {{cli}} upload . -p PC', 'upload PC Gadget in current folder'],
    ['$ {{cli}} upload . -t Gadget', 'upload Gadget in current folder'],
    [
        '$ {{cli}} upload . -p PC -v 1.0.0 -d fix',
        "upload PC Gadget in current folder, with version as 1.0.0 and description as 'fix'",
    ],
];
Upload.flags = {
    type: command_1.flags.enum({
        char: 't',
        description: 'project type',
        options: [enum_1.TypeEnum.Gadget, enum_1.TypeEnum.Block],
    }),
    platform: command_1.flags.enum({
        char: 'p',
        description: 'upload platform',
        required: false,
        options: enum_1.platform,
    }),
    version: command_1.flags.string({
        char: 'v',
        description: 'the value can be a version number such as 1.0.0, or one of (major|minor|patch), and the version number will be automatically incremented. "-v major" means the version number changed from 1.0.0 to 2.0.0, "-v minor" means the version number changed from 1.0.0 to 1.1.0, "-v patch" means the version number changed from 1.0.0 to 1.0.1',
    }),
    description: command_1.flags.string({
        char: 'd',
        description: 'version description, maximum length is 2048 characters, beyond that it will be truncated',
        default: '',
    }),
    help: command_1.flags.help({
        char: 'h',
    }),
    useNPM: command_1.flags.boolean({
        char: 'u',
        description: 'use npm',
        default: false,
    }),
};
Upload.args = [
    {
        name: 'path',
        required: true,
    },
];
