use crate::server::lsp::{
    CompletionItem, CompletionItemKind, CompletionList, InsertTextFormat, ItemDefaults,
};

use super::{CompletionEnvironment, error::CompletionError};

pub(super) async fn completions(
    _context: CompletionEnvironment,
) -> Result<CompletionList, CompletionError> {
    Ok(CompletionList {
        is_incomplete: false,
        item_defaults: Some(ItemDefaults {
            edit_range: None,
            commit_characters: None,
            data: None,
            insert_text_format: Some(InsertTextFormat::Snippet),
        }),
        items: vec![
            CompletionItem::new(
                "SELECT",
                Some("Select query".to_string()),
                None,
                "SELECT ${1:*} WHERE {\n  ${0:?s ?p ?o}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "CONSTRUCT",
                Some("Construct query".to_string()),
                None,
                "CONSTRUCT {\n  ${1:?s ?p ?o}\n} WHERE {\n  ${0:?s ?p ?o} .\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "ASK",
                Some("Ask query".to_string()),
                None,
                "ASK WHERE {\n  ${0:?s ?p ?o}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "DESCRIBE",
                Some("Describe query".to_string()),
                None,
                "DESCRIBE ?s WHERE {\n  ${0:?s ?p ?o}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Load",
                Some("Load query".to_string()),
                None,
                "LOAD <${0:iri}>;",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Clear",
                Some("Clear graph".to_string()),
                None,
                "CLEAR <${0:GraphRef}>;",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Drop",
                Some("Drop graph".to_string()),
                None,
                "DROP <${0:GraphRef}>;",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Add",
                Some("Add graph".to_string()),
                None,
                "ADD <${1:GraphRef}> TO <${0:GraphRef}>;",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Move",
                Some("Move graph".to_string()),
                None,
                "MOVE <${1:GraphRef}> TO <${0:GraphRef}>;",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Copy",
                Some("Copy graph".to_string()),
                None,
                "COPY <${1:GraphRef}> TO <${0:GraphRef}>;",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Insert data",
                Some("Insert data.".to_string()),
                None,
                "INSERT DATA {\n  ${0}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Delete data",
                Some("Delete data.".to_string()),
                None,
                "DELETE DATA {\n  ${0}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Delete where",
                Some("Delete data with a where clause.".to_string()),
                None,
                "DELETE WHERE {\n  ${0}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Insert where",
                Some("Insert with a where clause.".to_string()),
                None,
                "Insert {\n  ${1}\n}\nWHERE {\n  ${0}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Delte Modify",
                Some("Delete data with a where clause.".to_string()),
                None,
                "DELETE {\n  ${1}\n}\nINSERT {\n  ${2}\n}\nWHERE {\n  ${0}\n}",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "PREFIX",
                Some("Declare a namespace".to_string()),
                None,
                "PREFIX ${1:namespace}: <${0:iri}>",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "BASE",
                Some("Set the Base URI".to_string()),
                None,
                "BASE <${0}>",
                CompletionItemKind::Snippet,
                None,
            ),
            CompletionItem::new(
                "Query Metadata",
                Some("Target endpoint and query description".to_string()),
                None,
                "#+ summary: ${1}\n#+ endpoint: ${0}",
                CompletionItemKind::Snippet,
                None,
            ),
        ],
    })
}
