//! Github-backed implementation (stub).
//!
//! This module provides a GithubStorage skeleton that returns `NotImplemented` errors by default.
//! Fill with GitHub API logic (e.g., GraphQL or REST + commit to repo) when needed.

use anyhow::{Result, anyhow};
use async_trait::async_trait;

use sepora_core::{Calendar, Diary, Todo};

use crate::storage::Storage;

pub struct GithubStorage {
    repo: String,
    token: String,
}

impl GithubStorage {
    /// Construct from explicit values.
    pub fn new(repo: impl Into<String>, token: impl Into<String>) -> Self {
        Self {
            repo: repo.into(),
            token: token.into(),
        }
    }

    /// Convenience constructor using environment variables:
    /// - `GITHUB_REPO` (owner/repo)
    /// - `GITHUB_TOKEN`
    pub fn new_from_env() -> Self {
        let repo = std::env::var("GITHUB_REPO").unwrap_or_else(|_| "owner/repo".into());
        let token = std::env::var("GITHUB_TOKEN").unwrap_or_default();
        Self { repo, token }
    }
}

#[async_trait]
impl Storage for GithubStorage {
    async fn list_todos(&self) -> Result<Vec<Todo>> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn create_todo(&self, _todo: Todo) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn update_todo(&self, _todo: Todo) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn delete_todo(&self, _id: &str) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }

    async fn list_diaries(&self) -> Result<Vec<Diary>> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn create_diary(&self, _diary: Diary) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn update_diary(&self, _diary: Diary) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn delete_diary(&self, _id: &str) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }

    async fn list_calendars(&self) -> Result<Vec<Calendar>> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn create_calendar(&self, _cal: Calendar) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn update_calendar(&self, _cal: Calendar) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
    async fn delete_calendar(&self, _id: &str) -> Result<()> {
        Err(anyhow!("GithubStorage not implemented"))
    }
}
