using Invercargill; using Invercargill.Mapping; using InvercargillJson; namespace Statum.Model { /** * A Statum action. * * An action describes an HTTP request the frontend can perform. Actions are * embedded (by path) inside a snapshot's {@link SnapshotDto.public} data and * invoked via `stm-action`. The response to an action is a JSON array of * {@link DirectiveDto}s. */ public class ActionDto : Object { /** The URI to request. */ public string uri { get; set; } /** The HTTP verb to use. */ public string method { get; set; } /** * Base64-encoded data only readable by the application server (see * {@link Statum.Cryptography.EncryptionProvider}), carried to the server * via the `X-Statum-Private` header, or `null`/undefined if the action * carries no private payload. */ public string? @private { get; set; } /** * Serialises this action to a {@link JsonElement} so it can be embedded * as a value in a snapshot's public data (e.g. * `state.public_data["checkout"] = ref.to_element()`), where the client * resolves it via `stm-action` and echoes `private` back. */ public JsonElement to_element() throws GLib.Error { return new JsonElement.from_properties(get_mapper().map_from(this)); } /** * The {@link PropertyMapper} used to (de)serialise an {@link ActionDto}. */ public static PropertyMapper get_mapper() { return PropertyMapper.build_for(cfg => { cfg.map("uri", o => o.uri, (o, v) => o.uri = v); cfg.map("method", o => o.method, (o, v) => o.method = v); cfg.map("private", o => o.@private, (o, v) => o.@private = v) .undefined_when(o => o.@private == null) .when_undefined(o => o.@private = null) .when_null(o => o.@private = null); cfg.set_constructor(() => new ActionDto()); }); } } }