import { RpcMethod, JsonObject } from './commonTypes'; export type TemplatesService_List = RpcMethod; export type TemplatesService_Get = RpcMethod; export type TemplatesService_Create = RpcMethod; export type TemplatesService_Update = RpcMethod; export type TemplatesService_Delete = RpcMethod; /** * TemplatesService is the CRUD surface for saved * templates. A template is a named, reusable document scoped to an * application, optionally tagged with free-form categories. The document * itself is opaque to this service — any valid JSON object; the frontend * owns its schema. * * Addressing: templates are addressed by their string `code` only. The * numeric primary key never crosses the wire. `code` is generated by the * server on Create and returned in the response. * * Categories live in a separate table (one row per category string) and are * surfaced here as a flat repeated string on the template. They are scoped to * the application. */ export interface TemplatesService { /** * List templates for an application, with search, category filter, sorting * and pagination. */ List: TemplatesService_List; /** Get a single template by code. */ Get: TemplatesService_Get; /** Create a new template. The server generates and returns its code. */ Create: TemplatesService_Create; /** Update an existing template (PATCH semantics on scalar fields). */ Update: TemplatesService_Update; /** Delete a template (also removes its category rows). */ Delete: TemplatesService_Delete; } /** Template is the full template as returned by Get. */ export type Template = { /** Server-generated stable identifier. The numeric DB id is never exposed. */ code: string; /** Human-readable name, unique within the application. */ name: string; /** Optional free-form description. */ description?: string; /** * The template document itself: any valid JSON object, opaque to this * service. */ template: JsonObject; /** Category tags attached to this template. Order is not significant. */ categories: string[]; /** Creation timestamp. */ createdAt: Date; /** Last update timestamp. */ updatedAt: Date; }; export type ListRequest_OrderBy = 'UPDATED' | 'NAME' | 'CREATED'; export type ListRequest_OrderDirection = 'DESC' | 'ASC'; export type ListRequest = { /** Application code the templates belong to. */ application: string; /** Search query, matched against name and code. */ search: string; /** Optional category filter: only templates tagged with this category. */ category?: string; /** Field to order results by. */ orderBy: ListRequest_OrderBy; /** Order direction. */ orderDirection: ListRequest_OrderDirection; /** Page number. Pagination starts from 0. */ page: number; /** Number of items per page. */ perPage: number; }; /** * ListItem is a lightweight projection of a template for list views. The * full template document is intentionally omitted; fetch it with Get. */ export type ListResponse_ListItem = { code: string; name: string; description?: string; categories: string[]; createdAt: Date; updatedAt: Date; }; export type ListResponse = { /** Templates for the current page. */ items: ListResponse_ListItem[]; /** Current page number. Pagination starts from 0. */ page: number; /** Number of items per page. */ perPage: number; /** Total number of pages. */ totalPages: number; /** Total number of items across all pages. */ total: number; }; export type GetRequest = { /** Application code the template belongs to. */ application: string; /** Template code. */ code: string; }; export type GetResponse = { item: Template; }; export type CreateRequest = { /** Application code the template will belong to. */ application: string; /** Human-readable name, unique within the application. */ name: string; /** Optional free-form description. */ description?: string; /** The template document: any valid JSON object. */ template: JsonObject; /** Category tags to attach. May be empty. */ categories: string[]; }; export type CreateResponse = { /** Server-generated code of the created template. */ code: string; }; export type UpdateRequest = { /** Application code the template belongs to. */ application: string; /** Code of the template to update. */ code: string; /** New name. Only applied when set. */ name?: string; /** New description. Only applied when set. */ description?: string; /** * New template document (any valid JSON object). Only applied when set * (message presence). */ template: JsonObject; /** * Controls how categories is applied (PATCH semantics): * - true → replace categories with the provided list * (an empty list clears all categories). * - false → leave categories untouched. * Required because proto3 cannot distinguish an unset repeated field from * one explicitly set to an empty list. */ updateCategories: boolean; /** New category tags. Only applied when update_categories is true. */ categories: string[]; }; export type UpdateResponse = {}; export type DeleteRequest = { /** Application code the template belongs to. */ application: string; /** Code of the template to delete. */ code: string; }; export type DeleteResponse = {};