1/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package apply
18
19// TypeElement contains the recorded, local and remote values for a field
20// that is a complex type
21type TypeElement struct {
22	// FieldMetaImpl contains metadata about the field from openapi
23	FieldMetaImpl
24
25	MapElementData
26
27	// Values contains the combined recorded-local-remote value of each field in the type
28	// Values contains the values in mapElement.  Element must contain
29	// a Name matching its key in Values
30	Values map[string]Element
31}
32
33// Merge implements Element.Merge
34func (e TypeElement) Merge(v Strategy) (Result, error) {
35	return v.MergeType(e)
36}
37
38// GetValues implements Element.GetValues
39func (e TypeElement) GetValues() map[string]Element {
40	return e.Values
41}
42
43// HasConflict returns ConflictError if some elements in type conflict.
44func (e TypeElement) HasConflict() error {
45	for _, item := range e.GetValues() {
46		if item, ok := item.(ConflictDetector); ok {
47			if err := item.HasConflict(); err != nil {
48				return err
49			}
50		}
51	}
52	return nil
53}
54
55var _ Element = &TypeElement{}
56var _ ConflictDetector = &TypeElement{}
57