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

// PersonalAccessTokenRequest Personal Access Token Request.
type PersonalAccessTokenRequest struct {
	// Name of a token.
	Name string `json:"name"`
	// Expiration time in seconds (maximum one year - 31536000s). If you omit it or set it to zero, the Personal Access Token will never expire. 
	ExpiresIn *int32 `json:"expires_in,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _PersonalAccessTokenRequest PersonalAccessTokenRequest

// NewPersonalAccessTokenRequest instantiates a new PersonalAccessTokenRequest 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 NewPersonalAccessTokenRequest(name string) *PersonalAccessTokenRequest {
	this := PersonalAccessTokenRequest{}
	this.Name = name
	return &this
}

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

// GetName returns the Name field value
func (o *PersonalAccessTokenRequest) 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 *PersonalAccessTokenRequest) GetNameOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Name, true
}

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

// GetExpiresIn returns the ExpiresIn field value if set, zero value otherwise.
func (o *PersonalAccessTokenRequest) GetExpiresIn() int32 {
	if o == nil || IsNil(o.ExpiresIn) {
		var ret int32
		return ret
	}
	return *o.ExpiresIn
}

// GetExpiresInOk returns a tuple with the ExpiresIn field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *PersonalAccessTokenRequest) GetExpiresInOk() (*int32, bool) {
	if o == nil || IsNil(o.ExpiresIn) {
		return nil, false
	}
	return o.ExpiresIn, true
}

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

	return false
}

// SetExpiresIn gets a reference to the given int32 and assigns it to the ExpiresIn field.
func (o *PersonalAccessTokenRequest) SetExpiresIn(v int32) {
	o.ExpiresIn = &v
}

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

func (o PersonalAccessTokenRequest) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["name"] = o.Name
	if !IsNil(o.ExpiresIn) {
		toSerialize["expires_in"] = o.ExpiresIn
	}

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

	return toSerialize, nil
}

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

	varPersonalAccessTokenRequest := _PersonalAccessTokenRequest{}

	err = json.Unmarshal(data, &varPersonalAccessTokenRequest)

	if err != nil {
		return err
	}

	*o = PersonalAccessTokenRequest(varPersonalAccessTokenRequest)

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

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

	return err
}

type NullablePersonalAccessTokenRequest struct {
	value *PersonalAccessTokenRequest
	isSet bool
}

func (v NullablePersonalAccessTokenRequest) Get() *PersonalAccessTokenRequest {
	return v.value
}

func (v *NullablePersonalAccessTokenRequest) Set(val *PersonalAccessTokenRequest) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullablePersonalAccessTokenRequest(val *PersonalAccessTokenRequest) *NullablePersonalAccessTokenRequest {
	return &NullablePersonalAccessTokenRequest{value: val, isSet: true}
}

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

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


