use crate::error::TokenError;
use std::io::{self, IsTerminal, Write};
pub struct ConsentPrompt {
pub provider: &'static str,
pub api_endpoint: &'static str,
}
impl ConsentPrompt {
pub fn ask(&self) -> Result<bool, TokenError> {
if !io::stdin().is_terminal() {
return Err(TokenError::NonInteractiveWithoutYes {
model: "claude".to_string(), });
}
eprintln!();
eprintln!(
"This will send your input to {}'s API for accurate token counting.",
self.provider
);
eprintln!("Your input will be transmitted over HTTPS to: {}", self.api_endpoint);
eprintln!();
eprint!("Proceed with API call? (y/N): ");
io::stderr().flush().map_err(|e| {
TokenError::Io(io::Error::other(format!("Failed to flush stderr: {}", e)))
})?;
let mut response = String::new();
io::stdin().read_line(&mut response).map_err(TokenError::Io)?;
let normalized = response.trim().to_lowercase();
Ok(normalized == "y" || normalized == "yes")
}
}