// Removes `{owner, repo}` scopes whose owner is already declared as an `{org}` scope.
// Registering both would cause GitHub to deliver every PR event twice (one delivery
// per webhook), so we collapse to org-only for those repos. Other scopes pass through
// unchanged, preserving original input order.
//
// Comparison is case-insensitive: GitHub owner names are case-insensitive, so
// `orgs: [motivation-labs]` subsumes `repos: [Motivation-Labs/foo]`. The dropped map
// is keyed by the original-case org name from the `{org}` scope entry.
export function dedupScopes(input) {
    const orgs = new Map();
    for (const s of input) {
        if ('org' in s && !orgs.has(s.org.toLowerCase()))
            orgs.set(s.org.toLowerCase(), s.org);
    }
    const scopes = [];
    const dropped = new Map();
    const fallbackRepos = new Map();
    for (const s of input) {
        if ('org' in s) {
            scopes.push(s);
            continue;
        }
        const coveringOrg = orgs.get(s.owner.toLowerCase());
        if (coveringOrg) {
            const list = dropped.get(coveringOrg) ?? [];
            list.push(s.repo);
            dropped.set(coveringOrg, list);
            const fallbackList = fallbackRepos.get(coveringOrg) ?? [];
            fallbackList.push({ owner: s.owner, repo: s.repo });
            fallbackRepos.set(coveringOrg, fallbackList);
            continue;
        }
        scopes.push(s);
    }
    return { scopes, dropped, fallbackRepos };
}
//# sourceMappingURL=scopes.js.map