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

// Limit Limit definition
type Limit struct {
	Limit int32 `json:"limit"`
	AdditionalProperties map[string]interface{}
}

type _Limit Limit

// NewLimit instantiates a new Limit 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 NewLimit(limit int32) *Limit {
	this := Limit{}
	this.Limit = limit
	return &this
}

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

// GetLimit returns the Limit field value
func (o *Limit) GetLimit() int32 {
	if o == nil {
		var ret int32
		return ret
	}

	return o.Limit
}

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

// SetLimit sets field value
func (o *Limit) SetLimit(v int32) {
	o.Limit = v
}

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

func (o Limit) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["limit"] = o.Limit

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

	return toSerialize, nil
}

func (o *Limit) 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{
		"limit",
	}

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

	varLimit := _Limit{}

	err = json.Unmarshal(data, &varLimit)

	if err != nil {
		return err
	}

	*o = Limit(varLimit)

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

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

	return err
}

type NullableLimit struct {
	value *Limit
	isSet bool
}

func (v NullableLimit) Get() *Limit {
	return v.value
}

func (v *NullableLimit) Set(val *Limit) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableLimit(val *Limit) *NullableLimit {
	return &NullableLimit{value: val, isSet: true}
}

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

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


