/*
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 FilterV2 type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &FilterV2{}

// FilterV2 Inventory filter assigned to the deployment
type FilterV2 struct {
	// Unique identifier of the saved filter. 
	Id string `json:"id"`
	// Name of the saved filter. 
	Name string `json:"name"`
	Terms []AttributeFilterPredicate `json:"terms,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _FilterV2 FilterV2

// NewFilterV2 instantiates a new FilterV2 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 NewFilterV2(id string, name string) *FilterV2 {
	this := FilterV2{}
	this.Id = id
	this.Name = name
	return &this
}

// NewFilterV2WithDefaults instantiates a new FilterV2 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 NewFilterV2WithDefaults() *FilterV2 {
	this := FilterV2{}
	return &this
}

// GetId returns the Id field value
func (o *FilterV2) GetId() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Id
}

// GetIdOk returns a tuple with the Id field value
// and a boolean to check if the value has been set.
func (o *FilterV2) GetIdOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Id, true
}

// SetId sets field value
func (o *FilterV2) SetId(v string) {
	o.Id = v
}

// GetName returns the Name field value
func (o *FilterV2) GetName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Name
}

// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *FilterV2) GetNameOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Name, true
}

// SetName sets field value
func (o *FilterV2) SetName(v string) {
	o.Name = v
}

// GetTerms returns the Terms field value if set, zero value otherwise.
func (o *FilterV2) GetTerms() []AttributeFilterPredicate {
	if o == nil || IsNil(o.Terms) {
		var ret []AttributeFilterPredicate
		return ret
	}
	return o.Terms
}

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

// HasTerms returns a boolean if a field has been set.
func (o *FilterV2) HasTerms() bool {
	if o != nil && !IsNil(o.Terms) {
		return true
	}

	return false
}

// SetTerms gets a reference to the given []AttributeFilterPredicate and assigns it to the Terms field.
func (o *FilterV2) SetTerms(v []AttributeFilterPredicate) {
	o.Terms = v
}

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

func (o FilterV2) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["id"] = o.Id
	toSerialize["name"] = o.Name
	if !IsNil(o.Terms) {
		toSerialize["terms"] = o.Terms
	}

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

	return toSerialize, nil
}

func (o *FilterV2) 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{
		"id",
		"name",
	}

	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)
		}
	}

	varFilterV2 := _FilterV2{}

	err = json.Unmarshal(data, &varFilterV2)

	if err != nil {
		return err
	}

	*o = FilterV2(varFilterV2)

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

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

	return err
}

type NullableFilterV2 struct {
	value *FilterV2
	isSet bool
}

func (v NullableFilterV2) Get() *FilterV2 {
	return v.value
}

func (v *NullableFilterV2) Set(val *FilterV2) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableFilterV2(val *FilterV2) *NullableFilterV2 {
	return &NullableFilterV2{value: val, isSet: true}
}

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

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


