1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.testsupport.builder;
7   
8   import dev.metaschema.core.datatype.IDataTypeAdapter;
9   import dev.metaschema.core.model.IFlagDefinition;
10  import dev.metaschema.core.model.IFlagInstance;
11  import dev.metaschema.core.model.IModelDefinition;
12  import dev.metaschema.core.model.IModule;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  /**
16   * Represents a Metaschema module-based model builder for producing flag
17   * definitions and instances.
18   */
19  public interface IFlagBuilder extends IMetaschemaBuilder<IFlagBuilder> {
20  
21    /**
22     * Create a new builder using the provided mocking context.
23     *
24     * @return the new builder
25     */
26    @NonNull
27    static IFlagBuilder builder() {
28      return new FlagBuilder().reset();
29    }
30  
31    /**
32     * Apply the provided required setting to built flags.
33     *
34     * @param required
35     *          {@code true} if the flag is required or {@code false} otherwise
36     * @return this builder
37     */
38    IFlagBuilder required(boolean required);
39  
40    /**
41     * Apply the provided data type adapter to built flags.
42     *
43     * @param dataTypeAdapter
44     *          the data type adapter to use
45     * @return this builder
46     */
47    IFlagBuilder dataTypeAdapter(@NonNull IDataTypeAdapter<?> dataTypeAdapter);
48  
49    /**
50     * Apply the provided data type adapter to built flags.
51     *
52     * @param defaultValue
53     *          the default value to use
54     * @return this builder
55     */
56    IFlagBuilder defaultValue(@NonNull Object defaultValue);
57  
58    /**
59     * Build a mocked flag instance, based on a mocked definition, as a child of the
60     * provided parent.
61     *
62     * @param parent
63     *          the parent containing the new instance
64     * @return the new mocked instance
65     */
66    @NonNull
67    default IFlagInstance toInstance(@NonNull IModelDefinition parent) {
68      IFlagDefinition def = toDefinition();
69      return toInstance(parent, def);
70    }
71  
72    /**
73     * Build a mocked flag instance, using the provided definition, as a child of
74     * the provided parent.
75     *
76     * @param parent
77     *          the parent containing the new instance
78     * @param definition
79     *          the definition to base the instance on
80     * @return the new mocked instance
81     */
82    @NonNull
83    IFlagInstance toInstance(@NonNull IModelDefinition parent, @NonNull IFlagDefinition definition);
84  
85    /**
86     * Build a mocked flag definition.
87     *
88     * @return the new mocked definition
89     */
90    @NonNull
91    IFlagDefinition toDefinition();
92  
93    /**
94     * Build a mocked flag definition associated with the given module.
95     *
96     * @param module
97     *          the containing module
98     * @return the new mocked definition
99     */
100   @NonNull
101   IFlagDefinition toDefinition(@NonNull IModule module);
102 }