/*
Mender API

Combined API specification for the features of the different Mender backend services, suitable for code generation applications 

API version: 1
Contact: support@mender.io
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package client

import (
	"encoding/json"
	"fmt"
)

// checks if the FilterV1 type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &FilterV1{}

// FilterV1 Filter built based on devices targeted by the deployment. 
type FilterV1 struct {
	Terms []AttributeFilterPredicate `json:"terms"`
	AdditionalProperties map[string]interface{}
}

type _FilterV1 FilterV1

// NewFilterV1 instantiates a new FilterV1 object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewFilterV1(terms []AttributeFilterPredicate) *FilterV1 {
	this := FilterV1{}
	this.Terms = terms
	return &this
}

// NewFilterV1WithDefaults instantiates a new FilterV1 object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewFilterV1WithDefaults() *FilterV1 {
	this := FilterV1{}
	return &this
}

// GetTerms returns the Terms field value
func (o *FilterV1) GetTerms() []AttributeFilterPredicate {
	if o == nil {
		var ret []AttributeFilterPredicate
		return ret
	}

	return o.Terms
}

// GetTermsOk returns a tuple with the Terms field value
// and a boolean to check if the value has been set.
func (o *FilterV1) GetTermsOk() ([]AttributeFilterPredicate, bool) {
	if o == nil {
		return nil, false
	}
	return o.Terms, true
}

// SetTerms sets field value
func (o *FilterV1) SetTerms(v []AttributeFilterPredicate) {
	o.Terms = v
}

func (o FilterV1) MarshalJSON() ([]byte, error) {
	toSerialize,err := o.ToMap()
	if err != nil {
		return []byte{}, err
	}
	return json.Marshal(toSerialize)
}

func (o FilterV1) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["terms"] = o.Terms

	for key, value := range o.AdditionalProperties {
		toSerialize[key] = value
	}

	return toSerialize, nil
}

func (o *FilterV1) UnmarshalJSON(data []byte) (err error) {
	// This validates that all required properties are included in the JSON object
	// by unmarshalling the object into a generic map with string keys and checking
	// that every required field exists as a key in the generic map.
	requiredProperties := []string{
		"terms",
	}

	allProperties := make(map[string]interface{})

	err = json.Unmarshal(data, &allProperties)

	if err != nil {
		return err;
	}

	for _, requiredProperty := range(requiredProperties) {
		if _, exists := allProperties[requiredProperty]; !exists {
			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

	varFilterV1 := _FilterV1{}

	err = json.Unmarshal(data, &varFilterV1)

	if err != nil {
		return err
	}

	*o = FilterV1(varFilterV1)

	additionalProperties := make(map[string]interface{})

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "terms")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableFilterV1 struct {
	value *FilterV1
	isSet bool
}

func (v NullableFilterV1) Get() *FilterV1 {
	return v.value
}

func (v *NullableFilterV1) Set(val *FilterV1) {
	v.value = val
	v.isSet = true
}

func (v NullableFilterV1) IsSet() bool {
	return v.isSet
}

func (v *NullableFilterV1) Unset() {
	v.value = nil
	v.isSet = false
}

func NewNullableFilterV1(val *FilterV1) *NullableFilterV1 {
	return &NullableFilterV1{value: val, isSet: true}
}

func (v NullableFilterV1) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.value)
}

func (v *NullableFilterV1) UnmarshalJSON(src []byte) error {
	v.isSet = true
	return json.Unmarshal(src, &v.value)
}


