//! Tauri commands for PDF annotation CRUD.

use crate::state::AppState;
use brittle_core::{Annotation, AnnotationId, AnnotationType, ReferenceId};
use tauri::State;

#[tauri::command]
pub fn create_annotation(
    state: State<AppState>,
    reference_id: ReferenceId,
    page: u32,
    annotation_type: AnnotationType,
    content: Option<String>,
) -> Result<Annotation, String> {
    state.with_repo(|b| b.create_annotation(reference_id, page, annotation_type, content))
}

#[tauri::command]
pub fn get_annotations(
    state: State<AppState>,
    reference_id: ReferenceId,
) -> Result<Vec<Annotation>, String> {
    state.with_repo_read(|b| b.get_annotations(reference_id))
}

#[tauri::command]
pub fn update_annotation(
    state: State<AppState>,
    annotation: Annotation,
) -> Result<Annotation, String> {
    state.with_repo(|b| b.update_annotation(annotation))
}

#[tauri::command]
pub fn delete_annotation(
    state: State<AppState>,
    reference_id: ReferenceId,
    annotation_id: AnnotationId,
) -> Result<(), String> {
    state.with_repo(|b| b.delete_annotation(reference_id, annotation_id))
}
