/**
 * DraftOutreachPostUseCase — spec 097, FR-33.
 *
 * v1: Discord-only. Produces a draft message about a release / monthly
 * recap / milestone. Pure: returns text without sending. Posting is
 * routed through `IOutreachPublisher` and gated by
 * `IContributorActionGate` upstream.
 *
 * Reddit / HN / X drafting is deferred to a v2 spec (resolved
 * product-question 4).
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { inject, injectable } from 'tsyringe';
const DISCORD_BODY_HARD_LIMIT = 2000;
const DRAFT_TARGET_LENGTH = 1800;
const SYSTEM_PROMPT = [
    'You write short Discord announcements for the Shep open-source community.',
    'Tone: friendly, factual, never marketing-spammy. Include a clear call to action.',
    'Output is plain text in Discord-flavored markdown — no front-matter, no JSON.',
    `Hard limit: ${DRAFT_TARGET_LENGTH} characters; the channel rejects anything past 2000.`,
].join(' ');
let DraftOutreachPostUseCase = class DraftOutreachPostUseCase {
    agentProvider;
    constructor(agentProvider) {
        this.agentProvider = agentProvider;
    }
    async execute(input) {
        if (!input.title.trim()) {
            throw new Error('DraftOutreachPostUseCase requires a non-empty title.');
        }
        const executor = await this.agentProvider.getExecutor();
        const prompt = renderPrompt(input);
        const result = await executor.execute(prompt, { systemPrompt: SYSTEM_PROMPT });
        const body = clampToDiscordLimit(ensureContainsTitle(result.result, input.title));
        return { channel: 'discord', body };
    }
};
DraftOutreachPostUseCase = __decorate([
    injectable(),
    __param(0, inject('IAgentExecutorProvider')),
    __metadata("design:paramtypes", [Object])
], DraftOutreachPostUseCase);
export { DraftOutreachPostUseCase };
function renderPrompt(input) {
    const lines = [
        `Draft a Discord announcement of kind: ${input.kind}.`,
        `Title to feature prominently: ${input.title}`,
    ];
    if (input.highlights?.length) {
        lines.push('Highlights to mention:');
        for (const h of input.highlights)
            lines.push(`- ${h}`);
    }
    if (input.link)
        lines.push(`Link to include exactly once: ${input.link}`);
    lines.push(`Keep it under ${DRAFT_TARGET_LENGTH} characters.`);
    return lines.join('\n');
}
function ensureContainsTitle(body, title) {
    return body.includes(title) ? body : `${title}\n\n${body}`;
}
function clampToDiscordLimit(body) {
    if (body.length <= DISCORD_BODY_HARD_LIMIT)
        return body;
    return `${body.slice(0, DISCORD_BODY_HARD_LIMIT - 1).trimEnd()}…`;
}
