/**
 * GetContributorLeaderboardUseCase — spec 097, FR-38.
 *
 * Returns top contributors by PR count for a given scope (month / all-time)
 * with a configurable limit. Backs the web `ContributorLeaderboard`
 * component. Repository aggregation runs at request time (research
 * decision: no materialized view in v1).
 */
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 DEFAULT_LIMIT = 10;
const MAX_LIMIT = 100;
let GetContributorLeaderboardUseCase = class GetContributorLeaderboardUseCase {
    contributors;
    constructor(contributors) {
        this.contributors = contributors;
    }
    async execute(input) {
        const limit = clampLimit(input.limit);
        const rows = await this.contributors.findTopByPrCount({ scope: input.scope, limit });
        return {
            scope: input.scope,
            limit,
            entries: rows.map(toEntry),
        };
    }
};
GetContributorLeaderboardUseCase = __decorate([
    injectable(),
    __param(0, inject('IContributorRepository')),
    __metadata("design:paramtypes", [Object])
], GetContributorLeaderboardUseCase);
export { GetContributorLeaderboardUseCase };
function clampLimit(provided) {
    if (provided === undefined)
        return DEFAULT_LIMIT;
    if (!Number.isFinite(provided) || provided <= 0) {
        throw new Error(`limit must be a positive number; got ${provided}`);
    }
    return Math.min(Math.floor(provided), MAX_LIMIT);
}
function toEntry(c) {
    return {
        login: c.githubLogin,
        displayName: c.displayName,
        avatarUrl: c.avatarUrl,
        prCount: c.prCount,
        level: c.level,
        lane: c.lane,
    };
}
