use windmark_titanesque::response::Response;

use rust_i18n::t;

use crate::Url;

rust_i18n::i18n!("locales");

pub fn resp_redirect_root() -> Response {
    Response::temporary_redirect("/")
}

pub fn resp_nocert() -> Response {
    Response::success(t!("nocert"))
}

pub fn resp_noresults_for_query() -> Response {
    Response::success(t!("no_results_for_query"))
}

pub fn resp_db_query_error() -> Response {
    Response::temporary_failure(t!("no_results_for_query"))
}

pub fn resp_note_prompt_text() -> Response {
    Response::input(t!("note_prompt"))
}

pub fn resp_invalid_params() -> Response {
    Response::temporary_failure(t!("invalid_params"))
}

pub fn resp_error_generic() -> Response {
    Response::temporary_failure("Generic error")
}

pub fn resp_signer_error() -> Response {
    Response::temporary_failure("Signer error")
}

pub fn resp_error_send_note() -> Response {
    Response::temporary_failure("Failed to send note")
}

pub fn resp_fetch_events_error() -> Response {
    Response::temporary_failure("Failed to fetch events from relays")
}

pub fn dec_urlq(url: &Url) -> Option<String> {
    url.query()
        .map(|query| urlencoding::decode(query).unwrap().into())
}
