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.IAssemblyDefinition;
10  import dev.metaschema.core.model.IFieldDefinition;
11  import dev.metaschema.core.model.IFieldInstanceAbsolute;
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 field
17   * definitions and instances.
18   */
19  public interface IFieldBuilder extends IModelBuilder<IFieldBuilder> {
20  
21    /**
22     * Create a new builder using the provided mocking context.
23     *
24     * @return the new builder
25     */
26    @NonNull
27    static IFieldBuilder builder() {
28      return new FieldBuilder().reset();
29    }
30  
31    /**
32     * Apply the provided data type adapter to built fields.
33     *
34     * @param dataTypeAdapter
35     *          the data type adapter to use
36     * @return this builder
37     */
38    IFieldBuilder dataTypeAdapter(@NonNull IDataTypeAdapter<?> dataTypeAdapter);
39  
40    /**
41     * Apply the provided data type adapter to built fields.
42     *
43     * @param defaultValue
44     *          the default value to use
45     * @return this builder
46     */
47    IFieldBuilder defaultValue(@NonNull Object defaultValue);
48  
49    /**
50     * Build a mocked field instance, based on a mocked definition, as a child of
51     * the provided parent.
52     *
53     * @param parent
54     *          the parent containing the new instance
55     * @return the new mocked instance
56     */
57    @Override
58    @NonNull
59    IFieldInstanceAbsolute toInstance(@NonNull IAssemblyDefinition parent);
60  
61    /**
62     * Build a mocked field instance, using the provided definition, as a child of
63     * the provided parent.
64     *
65     * @param parent
66     *          the parent containing the new instance
67     * @param definition
68     *          the definition to base the instance on
69     * @return the new mocked instance
70     */
71    @NonNull
72    IFieldInstanceAbsolute toInstance(@NonNull IAssemblyDefinition parent, @NonNull IFieldDefinition definition);
73  
74    /**
75     * Build a mocked field definition.
76     *
77     * @return the new mocked definition
78     */
79    @NonNull
80    IFieldDefinition toDefinition();
81  
82    /**
83     * Build a mocked field definition associated with the given module.
84     *
85     * @param module
86     *          the containing module
87     * @return the new mocked definition
88     */
89    @NonNull
90    IFieldDefinition toDefinition(@NonNull IModule module);
91  }