/**
 * GetCuratedIssuesByLaneUseCase — spec 097, FR-37.
 *
 * Returns curated good-first-issues filtered by chosen lane. Backs the
 * web "pick your first issue" CTA. Stale issues (older than the
 * configured threshold) are excluded so newcomers do not land on
 * abandoned tickets.
 */
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';
import { ContributionDifficulty } from '../../../domain/generated/output.js';
const GOOD_FIRST_ISSUE_LABEL = 'good-first-issue';
const DEFAULT_STALE_DAYS = 30;
const MS_PER_DAY = 24 * 60 * 60 * 1000;
let GetCuratedIssuesByLaneUseCase = class GetCuratedIssuesByLaneUseCase {
    fetcher;
    constructor(fetcher) {
        this.fetcher = fetcher;
    }
    async execute(input) {
        const labels = [GOOD_FIRST_ISSUE_LABEL, `lane:${input.lane}`];
        const candidates = await this.fetcher.listIssuesByLabels(input.owner, input.repo, labels);
        const cutoff = (input.now?.getTime() ?? Date.now()) - (input.staleDays ?? DEFAULT_STALE_DAYS) * MS_PER_DAY;
        const issues = candidates
            .filter((issue) => Date.parse(issue.lastActivityAt) > cutoff)
            .map((issue) => toCurated(issue, input.lane));
        return { lane: input.lane, issues };
    }
};
GetCuratedIssuesByLaneUseCase = __decorate([
    injectable(),
    __param(0, inject('IExternalIssueFetcher')),
    __metadata("design:paramtypes", [Object])
], GetCuratedIssuesByLaneUseCase);
export { GetCuratedIssuesByLaneUseCase };
function toCurated(issue, lane) {
    return {
        owner: issue.owner,
        repo: issue.repo,
        issueNumber: issue.issueNumber,
        title: issue.title,
        url: issue.url,
        lane,
        difficulty: difficultyFromLabels(issue.labels),
    };
}
function difficultyFromLabels(labels) {
    const lc = labels.map((l) => l.toLowerCase());
    if (lc.includes('difficulty:hard') || lc.includes('hard'))
        return ContributionDifficulty.Hard;
    if (lc.includes('difficulty:medium') || lc.includes('medium')) {
        return ContributionDifficulty.Medium;
    }
    if (lc.includes('difficulty:easy') || lc.includes('easy'))
        return ContributionDifficulty.Easy;
    return ContributionDifficulty.GoodFirst;
}
