1package hclspec
2
3// ObjectSpec wraps the object and returns a spec.
4func ObjectSpec(obj *Object) *Spec {
5	return &Spec{
6		Block: &Spec_Object{
7			Object: obj,
8		},
9	}
10}
11
12// ArraySpec wraps the array and returns a spec.
13func ArraySpec(array *Array) *Spec {
14	return &Spec{
15		Block: &Spec_Array{
16			Array: array,
17		},
18	}
19}
20
21// AttrSpec wraps the attr and returns a spec.
22func AttrSpec(attr *Attr) *Spec {
23	return &Spec{
24		Block: &Spec_Attr{
25			Attr: attr,
26		},
27	}
28}
29
30// BlockSpec wraps the block and returns a spec.
31func BlockSpec(block *Block) *Spec {
32	return &Spec{
33		Block: &Spec_BlockValue{
34			BlockValue: block,
35		},
36	}
37}
38
39// BlockAttrsSpec wraps the block attrs and returns a spec.
40func BlockAttrsSpec(blockAttrs *BlockAttrs) *Spec {
41	return &Spec{
42		Block: &Spec_BlockAttrs{
43			BlockAttrs: blockAttrs,
44		},
45	}
46}
47
48// BlockListSpec wraps the block list and returns a spec.
49func BlockListSpec(blockList *BlockList) *Spec {
50	return &Spec{
51		Block: &Spec_BlockList{
52			BlockList: blockList,
53		},
54	}
55}
56
57// BlockSetSpec wraps the block set and returns a spec.
58func BlockSetSpec(blockSet *BlockSet) *Spec {
59	return &Spec{
60		Block: &Spec_BlockSet{
61			BlockSet: blockSet,
62		},
63	}
64}
65
66// BlockMapSpec wraps the block map and returns a spec.
67func BlockMapSpec(blockMap *BlockMap) *Spec {
68	return &Spec{
69		Block: &Spec_BlockMap{
70			BlockMap: blockMap,
71		},
72	}
73}
74
75// DefaultSpec wraps the default and returns a spec.
76func DefaultSpec(d *Default) *Spec {
77	return &Spec{
78		Block: &Spec_Default{
79			Default: d,
80		},
81	}
82}
83
84// LiteralSpec wraps the literal and returns a spec.
85func LiteralSpec(l *Literal) *Spec {
86	return &Spec{
87		Block: &Spec_Literal{
88			Literal: l,
89		},
90	}
91}
92
93// NewObject returns a new object spec.
94func NewObject(attrs map[string]*Spec) *Spec {
95	return ObjectSpec(&Object{
96		Attributes: attrs,
97	})
98}
99
100// NewAttr returns a new attribute spec.
101func NewAttr(name, attrType string, required bool) *Spec {
102	return AttrSpec(&Attr{
103		Name:     name,
104		Type:     attrType,
105		Required: required,
106	})
107}
108
109// NewBlock returns a new block spec.
110func NewBlock(name string, required bool, nested *Spec) *Spec {
111	return BlockSpec(&Block{
112		Name:     name,
113		Required: required,
114		Nested:   nested,
115	})
116}
117
118// NewBlockAttrs returns a new block attrs spec
119func NewBlockAttrs(name, elementType string, required bool) *Spec {
120	return BlockAttrsSpec(&BlockAttrs{
121		Name:     name,
122		Required: required,
123		Type:     elementType,
124	})
125}
126
127// NewBlockList returns a new block list spec that has no limits.
128func NewBlockList(name string, nested *Spec) *Spec {
129	return NewBlockListLimited(name, 0, 0, nested)
130}
131
132// NewBlockListLimited returns a new block list spec that limits the number of
133// blocks.
134func NewBlockListLimited(name string, min, max uint64, nested *Spec) *Spec {
135	return BlockListSpec(&BlockList{
136		Name:     name,
137		MinItems: min,
138		MaxItems: max,
139		Nested:   nested,
140	})
141}
142
143// NewBlockSet returns a new block set spec that has no limits.
144func NewBlockSet(name string, nested *Spec) *Spec {
145	return NewBlockSetLimited(name, 0, 0, nested)
146}
147
148// NewBlockSetLimited returns a new block set spec that limits the number of
149// blocks.
150func NewBlockSetLimited(name string, min, max uint64, nested *Spec) *Spec {
151	return BlockSetSpec(&BlockSet{
152		Name:     name,
153		MinItems: min,
154		MaxItems: max,
155		Nested:   nested,
156	})
157}
158
159// NewBlockMap returns a new block map spec.
160func NewBlockMap(name string, labels []string, nested *Spec) *Spec {
161	return BlockMapSpec(&BlockMap{
162		Name:   name,
163		Labels: labels,
164		Nested: nested,
165	})
166}
167
168// NewLiteral returns a new literal spec.
169func NewLiteral(value string) *Spec {
170	return LiteralSpec(&Literal{
171		Value: value,
172	})
173}
174
175// NewDefault returns a new default spec.
176func NewDefault(primary, defaultValue *Spec) *Spec {
177	return DefaultSpec(&Default{
178		Primary: primary,
179		Default: defaultValue,
180	})
181}
182
183// NewArray returns a new array spec.
184func NewArray(values []*Spec) *Spec {
185	return ArraySpec(&Array{
186		Values: values,
187	})
188}
189