// SPDX-License-Identifier: GPL-2.0-only
/*
 *  ppm/include/ppm/error.h
 *
 *  Copyright (C) 2026 Project Tick
 */

#ifndef PPM_ERROR_H
#define PPM_ERROR_H

#ifdef __cplusplus
extern "C" {
#endif

/*
 * ppm_error_t — canonical error code returned by every fallible ppm function.
 *
 * Functions return PPM_OK (0) on success. Negative values are reserved for
 * future expansion; callers must compare against the named constants rather
 * than against truthiness.
 */
typedef enum ppm_error {
    PPM_OK                  = 0,
    PPM_ERR_NOMEM           = 1,   /* allocation failed                       */
    PPM_ERR_IO              = 2,   /* read/write/open/close failed            */
    PPM_ERR_PARSE           = 3,   /* manifest, lockfile, or TOML malformed   */
    PPM_ERR_INVALID         = 4,   /* argument failed validation              */
    PPM_ERR_NOT_FOUND       = 5,   /* package, file, or key not present       */
    PPM_ERR_EXISTS          = 6,   /* would clobber an existing object        */
    PPM_ERR_PERMISSION      = 7,   /* EACCES / EPERM from the kernel          */
    PPM_ERR_CONFLICT        = 8,   /* one-version-rule violation              */
    PPM_ERR_UNSAT           = 9,   /* resolver found no satisfying assignment */
    PPM_ERR_HASH_MISMATCH   = 10,  /* SHA-512 of fetched bytes did not match  */
    PPM_ERR_SIG_INVALID     = 11,  /* Ed25519 signature failed verification   */
    PPM_ERR_NETWORK         = 12,  /* libcurl / libgit2 transport failure     */
    PPM_ERR_REGISTRY        = 13,  /* registry repo structurally invalid      */
    PPM_ERR_TXN_ABORT       = 14,  /* transaction journal forced a rollback   */
    PPM_ERR_UNSUPPORTED     = 15,  /* feature not compiled in / not on platform */
    PPM_ERR_INTERNAL        = 99,  /* invariant broken; report as a bug       */
} ppm_error_t;

/* Human-readable description of an error code. Never returns NULL. */
const char *ppm_strerror(ppm_error_t err);

#ifdef __cplusplus
}
#endif

#endif /* PPM_ERROR_H */
