#ifndef NAIL_LED_AIW_ADAPTER_H
#define NAIL_LED_AIW_ADAPTER_H

#include "aiw_soc_peer.h"
#include "nail_led_mapper.h"

#define NLM_AIW_MODEL_FRAME_MAGIC UINT32_C(0x414D4C4E)
#define NLM_AIW_MODEL_FRAME_VERSION 1u

/* Camera/model adapter-owned result. frame_handle must point to this object
 * until aiw_soc_peer_process() returns. The production camera adapter must
 * populate it from the frame captured for the current AI_REQUEST. */
typedef struct {
    uint32_t magic;
    uint16_t version;
    uint16_t reserved;
    uint32_t optical_calibration_id;
    uint64_t source_frame_seq;
    bool model_valid;
    bool hand_present;
    uint8_t model_confidence;
    const uint8_t *nail_probability;
} nlm_aiw_model_frame;

typedef struct {
    const nlm_profile *profile;
    const nlm_policy *policy;
    uint32_t expected_calibration_id;
    uint64_t last_accepted_frame_seq;
} nlm_aiw_mapper_context;

/* Initialize only with a real, factory-measured optical profile and a policy
 * whose calibration IDs match. Returns false for an uncalibrated profile.
 * Keep profile/policy storage immutable and serialize callback invocations. */
bool nlm_aiw_mapper_init(nlm_aiw_mapper_context *context,
                         const nlm_profile *profile,
                         const nlm_policy *policy,
                         uint32_t expected_calibration_id);

/* Drop-in aiw_soc_infer_fn implementation. Invalid, uncalibrated, stale, or
 * low-confidence inputs return false; the peer then serializes a zero result. */
bool nlm_aiw_mapper_infer(void *context, const aiw_soc_capture *capture,
                          uint16_t channels, aiw_soc_inference *inference);

#endif
