//! atproto-static-web   A simple web viewer for AT Proto.
//! Copyright (C) 2025  AverageHelper
//!
//! This program is free software: you can redistribute it and/or modify
//! it under the terms of the GNU General Public License as published by
//! the Free Software Foundation, either version 3 of the License, or
//! (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program.  If not, see <https://www.gnu.org/licenses/>.

use reqwest::StatusCode;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct ErrorRes {
	pub error: ErrorResCode,
	pub message: String,
}

impl ErrorRes {
	pub const fn status(&self) -> StatusCode {
		match self.error {
			ErrorResCode::AuthMissing => StatusCode::UNAUTHORIZED,
			ErrorResCode::ExpiredToken => StatusCode::UNAUTHORIZED,
			ErrorResCode::InternalServerError => StatusCode::BAD_GATEWAY,
			ErrorResCode::InvalidToken => StatusCode::UNAUTHORIZED,
			ErrorResCode::InvalidRequest => StatusCode::BAD_REQUEST,
			ErrorResCode::NotFound => StatusCode::NOT_FOUND,
		}
	}
}

#[derive(Deserialize)]
pub enum ErrorResCode {
	AuthMissing,
	InternalServerError,
	InvalidRequest,
	ExpiredToken,
	InvalidToken,
	NotFound,
}
