"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatTaskLogLine = formatTaskLogLine;
exports.printTaskSummary = printTaskSummary;
exports.printPublishedAppNextSteps = printPublishedAppNextSteps;
const STATUS_EMOJI = {
    success: '✅',
    skipped: '➖',
    blocked: '⛔',
    error: '❌',
};
const ACTION_VERBS = {
    validate: {
        success: 'validated',
        skipped: 'skipped',
        blocked: 'blocked',
        error: '',
    },
    build: {
        success: 'built',
        skipped: 'skipped',
        blocked: 'blocked',
        error: '',
    },
    format: {
        success: 'formatted',
        skipped: 'skipped',
        blocked: 'blocked',
        error: '',
    },
    upload: {
        success: '',
        skipped: '',
        blocked: '',
        error: '',
    },
};
function formatLabel(entry) {
    const base = entry.entityType;
    const verb = ACTION_VERBS[entry.action]?.[entry.status] ?? '';
    const labelParts = verb ? [base, verb] : [base];
    return `${labelParts.join(' ')} ${entry.entityId}`.trim();
}
function formatTaskLogLine(entry) {
    const prefix = `${STATUS_EMOJI[entry.status]} ${formatLabel(entry)}`;
    if (entry.detail) {
        return `${prefix} - ${entry.detail}`;
    }
    return prefix;
}
function summarize(entries) {
    let success = 0;
    let skipped = 0;
    let blocked = 0;
    let failed = 0;
    for (const entry of entries) {
        if (entry.status === 'success')
            success += 1;
        if (entry.status === 'skipped')
            skipped += 1;
        if (entry.status === 'blocked')
            blocked += 1;
        if (entry.status === 'error')
            failed += 1;
    }
    return { success, skipped, blocked, failed };
}
function printTaskSummary(entries, warnings, options) {
    const warningList = Array.from(warnings);
    for (const warning of warningList) {
        if (warning) {
            console.log(`⚠️ ${warning}`);
        }
    }
    const { success, skipped, blocked, failed } = summarize(entries);
    const actionLabels = {
        validate: {
            complete: 'Validation complete',
            error: 'Validation finished with errors',
            none: 'No entries validated',
            unit: 'validated',
        },
        build: {
            complete: 'Build complete',
            error: 'Build finished with errors',
            none: 'No entries built',
            unit: 'built',
        },
        format: {
            complete: 'Format complete',
            error: 'Format finished with errors',
            none: 'No entries formatted',
            unit: 'formatted',
        },
        upload: {
            complete: 'Upload complete',
            error: 'Upload finished with errors',
            none: 'No changes uploaded',
            unit: 'uploaded',
        },
    };
    const labels = actionLabels[options.action];
    let summaryEmoji;
    let summaryText;
    if (failed > 0 || blocked > 0) {
        summaryEmoji = '❌';
        summaryText = labels.error;
        process.exitCode = process.exitCode || 1;
    }
    else if (success === 0) {
        summaryEmoji = '➖';
        summaryText = labels.none;
    }
    else {
        summaryEmoji = '✅';
        summaryText = labels.complete;
    }
    const parts = [
        `${summaryEmoji} ${summaryText} - ${success} ${labels.unit}`,
        `${skipped} skipped`,
        `${blocked} blocked`,
        `${failed} failed`,
    ];
    if (options.action === 'upload' && options.environment) {
        parts[0] = `${parts[0]} (env ${options.environment})`;
    }
    console.log(parts.join(', '));
}
function printPublishedAppNextSteps(entries) {
    const apps = entries.filter((entry) => entry.status === 'success' && entry.entityType === 'app' && entry.playUrl);
    for (const entry of apps) {
        const playUrl = entry.playUrl;
        console.log('');
        console.log(`Next steps for ${entry.entityId}:`);
        console.log(`- Manually test the game at ${playUrl} and make sure it is working and up to spec.`);
        console.log(`- Once satisfied, share the game URL on social media to start having people play it: ${playUrl}`);
        console.log('- Publish the code on GitHub in a public repo with the playable game link in the README.');
        console.log('- Set up automation to check player feedback every day using play count, likes, and comments, then come up with improvement ideas from it.');
        console.log('- Send feedback to Playdrop with "playdrop feedback send" for any bugs or improvement ideas you encountered.');
    }
}
