import { addRelayHintsToPointer, DATE_BASED_CALENDAR_EVENT_KIND, getAddressPointerForEvent, isAddressPointer, TIME_BASED_CALENDAR_EVENT_KIND, } from "applesauce-core/helpers";
import { createATagFromAddressPointer, createETagFromEventPointer, createPTagFromProfilePointer, } from "../helpers/pointer.js";
import { setSingletonTag } from "./tag/common.js";
import { includeSingletonTag, modifyPublicTags } from "./tags.js";
/** Sets the RSVP status for a calendar event */
export function setStatus(status) {
    return includeSingletonTag(["status", status], true);
}
/** Sets the free busy status for a calendar event */
export function setFreeBusy(freeBusy) {
    return includeSingletonTag(["fb", freeBusy], true);
}
/** Sets the pointers to the calendar event for an RSVP event */
export function setCalendarEvent(pointer, relay) {
    if (pointer.kind !== DATE_BASED_CALENDAR_EVENT_KIND && pointer.kind !== TIME_BASED_CALENDAR_EVENT_KIND)
        throw new Error("RSVP pointer must be to a calendar event");
    let addressPointer = isAddressPointer(pointer) ? pointer : getAddressPointerForEvent(pointer);
    let eventPointer = isAddressPointer(pointer)
        ? undefined
        : { id: pointer.id, kind: pointer.kind, author: pointer.pubkey };
    let profilePointer = { pubkey: pointer.pubkey };
    // Add relay hint if provided
    if (relay) {
        addressPointer = addRelayHintsToPointer(addressPointer, [relay]);
        if (eventPointer)
            eventPointer = addRelayHintsToPointer(eventPointer, [relay]);
        profilePointer = addRelayHintsToPointer(profilePointer, [relay]);
    }
    return modifyPublicTags(
    // Include "a" and "e" tags for calendar event
    setSingletonTag(createATagFromAddressPointer(addressPointer)), eventPointer ? setSingletonTag(createETagFromEventPointer(eventPointer)) : undefined, 
    // Add a "p" tag for the event author
    setSingletonTag(createPTagFromProfilePointer(profilePointer), true));
}
