"""Proposal data access functions."""
from __future__ import annotations

from ietf_analyzer.db import Database


def get_all_proposals(db: Database) -> list[dict]:
    """Return all proposals with linked gap info."""
    proposals = db.all_proposals()
    gaps = {g["id"]: g for g in db.all_gaps()}
    for p in proposals:
        p["gaps"] = [gaps[gid] for gid in p.get("gap_ids", []) if gid in gaps]
    return proposals

def get_proposal_detail(db: Database, proposal_id: int) -> dict | None:
    """Return a single proposal with full gap details."""
    p = db.get_proposal(proposal_id)
    if not p:
        return None
    gaps = {g["id"]: g for g in db.all_gaps()}
    p["gaps"] = [gaps[gid] for gid in p.get("gap_ids", []) if gid in gaps]
    return p

def get_proposals_for_gap(db: Database, gap_id: int) -> list[dict]:
    """Return proposals linked to a specific gap."""
    return db.get_proposals_for_gap(gap_id)
