// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0 import { implement } from "@conusai-kit/core" import * as c from "../contract/index.js" import { operationKey, transitionInvoice, updateDraft, validateTerms } from "../core/invoices.js" import { invoicingServiceOf } from "./service.js" export const INVOICING_PROCEDURES = [ implement(c.invoices, ({ ctx, input }) => invoicingServiceOf(ctx.container, ctx.kind).list(input.after)), implement(c.invoice, ({ ctx, input }) => invoicingServiceOf(ctx.container, ctx.kind).get(input.invoiceId)), implement(c.series, ({ ctx, input }) => invoicingServiceOf(ctx.container, ctx.kind).series(input.after)), implement(c.ubl, ({ ctx, input }) => invoicingServiceOf(ctx.container, ctx.kind).ubl(input.invoiceId)), implement(c.draft, ({ ctx, input }) => invoicingServiceOf(ctx.container, "effect").draft( validateTerms(input.data), operationKey("draft", input.requestId), ), ), implement(c.update, ({ ctx, input }) => updateDraft(invoicingServiceOf(ctx.container, "effect"), input)), implement(c.issue, ({ ctx, input }) => transitionInvoice(invoicingServiceOf(ctx.container, "effect"), "issue", input), ), implement(c.credit, ({ ctx, input }) => transitionInvoice(invoicingServiceOf(ctx.container, "effect"), "credit", input), ), implement(c.voidInvoice, ({ ctx, input }) => transitionInvoice(invoicingServiceOf(ctx.container, "effect"), "void", input), ), implement(c.createSeries, ({ ctx, input }) => invoicingServiceOf(ctx.container, "effect").createSeries({ ...input, key: operationKey("series", input.requestId), }), ), ]