1: <?php
2:
3: namespace LaravelUi5\Core\Ui5\Contracts;
4:
5: use LaravelUi5\Core\Contracts\ParameterizableInterface;
6: use LaravelUi5\Core\Enums\HttpMethod;
7: use LaravelUi5\Core\Ui5\Capabilities\ActionHandlerInterface;
8: use LaravelUi5\Core\Ui5\Capabilities\SluggableInterface;
9:
10: /**
11: * Contract for UI5 Actions.
12: *
13: * A UI5 Action represents a state-changing operation that can be invoked
14: * from a UI5 client via the generic API dispatcher. Typical examples are:
15: * - "toggle-lock" on a user
16: * - "approve-invoice"
17: * - "discard-draft"
18: *
19: * Characteristics:
20: * - Actions are always *mutating* operations (never pure reads).
21: * - Therefore, they must only be exposed as *POST endpoints*.
22: * - Route parameters (IDs, slugs) are declared on the ActionHandler and resolved
23: * via {@see ParameterizableInterface}. The dispatcher validates and
24: * injects these before calling the handler.
25: * - Body parameters (form data, payloads) are validated *inside the
26: * ActionHandler*, following Laravel best practices.
27: *
28: * Responsibilities:
29: * - Define the action’s slug (via {@see SluggableInterface}).
30: * - Provide the {@see ActionHandlerInterface} that executes the logic.
31: *
32: * Each Action must have a unique slug within its module. The slug is used
33: * to generate the manifest entry and the API route.
34: */
35: interface Ui5ActionInterface extends Ui5ArtifactInterface, SluggableInterface
36: {
37: /**
38: * Returns the HTTP method for calling this Action.
39: *
40: * Valid values:
41: * - POST, verb create
42: * - PATCH, verb update
43: * - DELETE, verb delete.
44: *
45: * @return HttpMethod
46: */
47: public function getMethod(): HttpMethod;
48:
49: /**
50: * Returns the ActionHandler responsible for executing this Action.
51: *
52: * Handlers encapsulate the runtime logic and must return a structured
53: * result array, e.g.:
54: *
55: * ```php
56: * ['status' => 'success', 'message' => 'Mailbox cleared']
57: * ```
58: *
59: * @return ActionHandlerInterface
60: */
61: public function getHandler(): ActionHandlerInterface;
62: }
63: