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

#ifndef PPM_LOCKFILE_H
#define PPM_LOCKFILE_H

#include <stddef.h>

#include <ppm/error.h>
#include <ppm/manifest.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Lockfile — the deterministic, fully-resolved dependency graph that pins
 * exact versions and tarball hashes. Same ppm.toml + same registry commit
 * must always produce the same lockfile, byte-for-byte.
 */

typedef struct ppm_lock_entry {
    char           *name;
    ppm_version_t   version;
    ppm_sha512_t    hash;         /* tarball hash                     */
    char           *source_url;
    char          **deps;         /* NULL-terminated list of names    */
} ppm_lock_entry_t;

typedef struct ppm_lockfile {
    uint32_t           schema;     /* always 1 in this release       */
    char              *registry_commit;  /* git SHA-1 hex            */
    ppm_lock_entry_t  *entries;
    size_t             entries_len;
} ppm_lockfile_t;

ppm_error_t ppm_lockfile_load (const char *path, ppm_lockfile_t **out);
ppm_error_t ppm_lockfile_save (const char *path, const ppm_lockfile_t *lock);
void        ppm_lockfile_free (ppm_lockfile_t *lock);

#ifdef __cplusplus
}
#endif

#endif /* PPM_LOCKFILE_H */
