import { v4 as uuid } from "uuid";
import { humanId } from "./human-id/human-id.js";
/**
 * create v2 Bundle with a random human ID
 *
 * @deprecated
 *
 * use the database directly
 *
 * - less code because the database has default values
 * - `createMessage` is misleading because it does not treat expressions in the text
 *
 * @example createBundle({
 *   messages: [
 * 		 createMessage({locale: "en", text: "Hello world!"})
 * 		 createMessage({locale: "de", text: "Hallo Welt!"})
 *   ]
 * })
 */
export function createBundle(args) {
    return {
        id: args.id ?? humanId(),
        messages: args.messages,
    };
}
/**
 *
 * @deprecated
 * use the database directly
 *
 * - text will always be a string, no matter
 *   if an expression is provided like hello "{username}"
 * - the database has default values
 *
 * ```
 * await project.db.insertInto("message").values({
 * 		bundleId: "bundleId",
 *    pattern: []
 * 		...
 * })
 * ```
 *
 * create v2 Messsage AST with a randomId, and text-only pattern
 * @example createMessage({locale: "en", text: "Hello world"})
 */
export function createMessage(args) {
    const messageId = uuid();
    return {
        bundleId: args.bundleId,
        id: messageId,
        locale: args.locale,
        selectors: [],
        variants: [
            createVariant({
                messageId: messageId,
                text: args.text,
                matches: args.matches,
            }),
        ],
    };
}
/**
 *
 * @deprecated
 *
 * use the database directly
 *
 * - less code because the database has default values
 * - `text` is misleading because it does not treat expressions in the text
 *
 * create v2 Variant AST with text-only pattern
 * @example createVariant({match: ["*"], text: "Hello world"})
 */
export function createVariant(args) {
    return {
        messageId: args.messageId,
        id: args.id ? args.id : uuid(),
        matches: args.matches ? args.matches : [],
        pattern: args.pattern ? args.pattern : [toTextElement(args.text ?? "")],
    };
}
export function toTextElement(text) {
    return {
        type: "text",
        value: text,
    };
}
//# sourceMappingURL=helper.js.map