/*
Hindsight HTTP API

HTTP API for Hindsight

API version: 0.4.17
*/

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

package hindsight

import (
	"encoding/json"
	"bytes"
	"fmt"
)

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

// TagItem Single tag with usage count.
type TagItem struct {
	// The tag value
	Tag string `json:"tag"`
	// Number of memories with this tag
	Count int32 `json:"count"`
}

type _TagItem TagItem

// NewTagItem instantiates a new TagItem 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 NewTagItem(tag string, count int32) *TagItem {
	this := TagItem{}
	this.Tag = tag
	this.Count = count
	return &this
}

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

// GetTag returns the Tag field value
func (o *TagItem) GetTag() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Tag
}

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

// SetTag sets field value
func (o *TagItem) SetTag(v string) {
	o.Tag = v
}

// GetCount returns the Count field value
func (o *TagItem) GetCount() int32 {
	if o == nil {
		var ret int32
		return ret
	}

	return o.Count
}

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

// SetCount sets field value
func (o *TagItem) SetCount(v int32) {
	o.Count = v
}

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

func (o TagItem) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["tag"] = o.Tag
	toSerialize["count"] = o.Count
	return toSerialize, nil
}

func (o *TagItem) 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{
		"tag",
		"count",
	}

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

	varTagItem := _TagItem{}

	decoder := json.NewDecoder(bytes.NewReader(data))
	decoder.DisallowUnknownFields()
	err = decoder.Decode(&varTagItem)

	if err != nil {
		return err
	}

	*o = TagItem(varTagItem)

	return err
}

type NullableTagItem struct {
	value *TagItem
	isSet bool
}

func (v NullableTagItem) Get() *TagItem {
	return v.value
}

func (v *NullableTagItem) Set(val *TagItem) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableTagItem(val *TagItem) *NullableTagItem {
	return &NullableTagItem{value: val, isSet: true}
}

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

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


