import type { NostrEvent as NostrToolsNostrEvent } from "nostr-tools";

export type ETag = ["e", string] | ["e", string, string] | ["e", string, string, string];
export type ATag = ["a", string] | ["a", string, string] | ["e", string, string, string];
export type PTag = ["p", string] | ["p", string, string] | ["p", string, string, string];
export type RTag = ["r", string] | ["r", string, string];
export type DTag = ["d", string];
export type ExpirationTag = ["expiration", string];
export type EmojiTag = ["emoji", string, string];
export type Tag = string[] | ETag | PTag | RTag | DTag | ATag | ExpirationTag;

export type NostrEvent = Omit<NostrToolsNostrEvent, "tags"> & {
  tags: Tag[];
};

export type DraftNostrEvent = Omit<NostrEvent, "pubkey" | "id" | "sig"> & { pubkey?: string; id?: string };

export function isETag(tag: Tag): tag is ETag {
  return tag[0] === "e" && tag[1] !== undefined;
}
export function isPTag(tag: Tag): tag is PTag {
  return tag[0] === "p" && tag[1] !== undefined;
}
export function isRTag(tag: Tag): tag is RTag {
  return tag[0] === "r" && tag[1] !== undefined;
}
export function isDTag(tag: Tag): tag is DTag {
  return tag[0] === "d" && tag[1] !== undefined;
}
export function isATag(tag: Tag): tag is ATag {
  return tag[0] === "a" && tag[1] !== undefined;
}
export function isEmojiTag(tag: Tag): tag is EmojiTag {
  return tag[0] === "emoji" && tag[1] !== undefined && tag[2] !== undefined;
}
