View Javadoc
1   package com.guinetik.hexafun.hexa;
2   
3   /**
4    * Builder step for defining the input handling of a use case.
5    *
6    * <p>From here you can:
7    * <ul>
8    *   <li>{@link #validate(ValidationPort)} - Add validation before handling</li>
9    *   <li>{@link #handle(UseCase)} - Go directly to handler (no validation)</li>
10   * </ul>
11   *
12   * @param <I> The input type of the use case
13   * @param <O> The output type of the use case
14   */
15  public class UseCaseInputStep<I, O> {
16  
17      private final String name;
18      private final UseCaseBuilder builder;
19  
20      public UseCaseInputStep(String name, UseCaseBuilder builder) {
21          this.name = name;
22          this.builder = builder;
23      }
24  
25      /**
26       * Define the core logic of the use case without validation.
27       *
28       * @param handler The use case logic that processes the input and produces output
29       * @param <R> The output type of the use case
30       * @return The builder for chaining more use cases
31       */
32      public <R> UseCaseBuilder handle(UseCase<I, R> handler) {
33          builder.stage(name, handler);
34          return builder;
35      }
36  
37      /**
38       * Add a validation step before the handler.
39       *
40       * @param validator The validation port that checks the input
41       * @return The validation step for chaining more validators or the handler
42       */
43      public UseCaseValidationStep<I> validate(ValidationPort<I> validator) {
44          return new UseCaseValidationStep<>(name, builder, validator);
45      }
46  }