// SPDX-License-Identifier: GPL-2.0-only
/*
 *  ppm/src/cmd/verify.c
 *
 *  Re-check store layout integrity.
 *
 *  Copyright (C) 2026 Project Tick
 */

#include <ppm/store.h>

#include <stdio.h>

#include "../cli.h"
#include "../util/log.h"
#include "common.h"

int ppm_cmd_verify(int argc, char **argv) {
    (void)argc; (void)argv;
    ppm_store_t *store = NULL;
    if (ppm_cmd_open_store(&store) != PPM_OK) {
        ppm_error("could not open store");
        return 1;
    }
    int bad = 0;
    ppm_error_t err = ppm_store_verify(store, &bad);
    ppm_store_close(store);
    if (err) {
        ppm_error("verify: %s", ppm_strerror(err));
        return 1;
    }
    if (bad == 0) {
        ppm_info("store layout is consistent");
        return 0;
    }
    ppm_error("store has %d malformed entries", bad);
    return 1;
}
