import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/ae_api/api';

const ae_promises: key_val = {};

/**
 * create_ae_obj__event_person
 * Creates a new event_person record linked to an event.
 * Used as the first step of manual one-off badge creation.
 * The returned event_person_id is then passed to create_ae_obj__event_badge.
 */
export async function create_ae_obj__event_person({
    api_cfg,
    event_id,
    data_kv,
    params = {},
    log_lvl = 0
}: {
    api_cfg: any;
    event_id: string;
    data_kv: key_val;
    params?: key_val;
    log_lvl?: number;
}): Promise<any | null> {
    if (log_lvl) {
        console.log(
            `*** create_ae_obj__event_person() *** event_id=${event_id}`
        );
    }

    ae_promises.create__event_person = await api.create_nested_obj({
        api_cfg,
        parent_type: 'event',
        parent_id: event_id,
        child_type: 'event_person',
        fields: data_kv,
        params,
        log_lvl
    });

    return ae_promises.create__event_person;
}
