/*
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[doc = "API errors are in the 1XXXX range"]
#[derive(Debug, Serialize, Deserialize, Error)]
pub enum APIError {
    // general errors
    #[doc = "Should never be used, but still exists just in case"]
    #[error("undefined error")]
    Undefined = 10000,
    #[doc = "Authorization doesn't meet requirements"]
    #[error("not authorized")]
    NotAuthorized = 10001,
    #[doc = "Authorization is missing from the request"]
    #[error("missing authorization")]
    MissingAuthorization = 10002,
    #[doc = "For when pool.get() fails"]
    #[error("database pool get failed")]
    DatabasePoolGetFailed = 10003,
    // user related errors
    #[doc = "User does not exist in the database"]
    #[error("user not found")]
    UserNotFound = 11000,
    #[doc = "Invalid credentials were passed"]
    #[error("invalid credentials")]
    UserInvalidCredentials = 11001,
    #[doc = "Argon2 failed somehow"]
    #[error("password hash failed")]
    UserPasswordHashFailed = 11002,
    #[doc = "Argon2 verify_password failed somehow"]
    #[error("password check failed")]
    UserPasswordCheckFailed = 11003,
    // login/register errors
    #[doc = ""]
    #[error("invalid email")]
    UserEmailInvalid = 11100,
    #[doc = ""]
    #[error("username should not be shorter than 3 characters")]
    UserUsernameTooShort = 11101,
    #[doc = ""]
    #[error("password should not be shorter than 8 characters")]
    UserPasswordTooShort = 11102,
    #[doc = ""]
    #[error("user creation failed")]
    UserCreationFailed = 11103,
}