//! ReviewProvider trait and LLM integration.
//!
//! # Bounded Context: LLM Providers
//!
//! Owns the `ReviewProvider` trait, rig-core client construction,
//! prompt dispatch, and response parsing. Abstracts the 19-provider
//! matrix behind a single `review()` call — callers never touch
//! rig-core types directly.

pub mod response;
pub mod rig;

use async_trait::async_trait;
use thiserror::Error;

use crate::models::AgentDefinition;
use crate::models::finding::Finding;

/// Errors from the review provider.
#[derive(Error, Debug)]
pub enum ProviderError {
    #[error("LLM API error: {0}")]
    ApiError(String),

    #[error("failed to parse LLM response: {0}")]
    ParseError(String),

    #[error("provider not configured: {0}")]
    NotConfigured(String),
}

/// Trait for LLM-backed code review.
///
/// Implementations handle agent construction, prompt building,
/// and response parsing.
#[async_trait]
pub trait ReviewProvider: Send + Sync {
    /// Perform a code review and return findings.
    ///
    /// When `agentic` is true, `max_turns` and `max_tool_calls` control
    /// the budget for the agentic exploration loop.
    async fn review(
        &self,
        agent: &AgentDefinition,
        prompt: &str,
        agentic: bool,
        max_turns: usize,
        max_tool_calls: usize,
    ) -> Result<Vec<Finding>, ProviderError>;

    /// Perform a simple one-shot completion (non-agentic, no tool calls).
    ///
    /// Used for internal tasks like threat triage where the response is
    /// not a findings array but a custom JSON format.
    async fn complete(
        &self,
        system_prompt: &str,
        user_prompt: &str,
    ) -> Result<String, ProviderError>;
}
