/*
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"
	"time"
	"fmt"
)

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

// PersonalAccessToken Personal Access Token Object.
type PersonalAccessToken struct {
	// Token identifier.
	Id string `json:"id"`
	// Name of a token.
	Name string `json:"name"`
	// Date of last usage of a token. The accuracy is 5 minutes. 
	LastUsed *time.Time `json:"last_used,omitempty"`
	// Expiration date.
	ExpirationDate time.Time `json:"expiration_date"`
	// Server-side timestamp of the token creation. 
	CreatedTs time.Time `json:"created_ts"`
	AdditionalProperties map[string]interface{}
}

type _PersonalAccessToken PersonalAccessToken

// NewPersonalAccessToken instantiates a new PersonalAccessToken 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 NewPersonalAccessToken(id string, name string, expirationDate time.Time, createdTs time.Time) *PersonalAccessToken {
	this := PersonalAccessToken{}
	this.Id = id
	this.Name = name
	this.ExpirationDate = expirationDate
	this.CreatedTs = createdTs
	return &this
}

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

// GetId returns the Id field value
func (o *PersonalAccessToken) 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 *PersonalAccessToken) GetIdOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Id, true
}

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

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

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

// GetLastUsed returns the LastUsed field value if set, zero value otherwise.
func (o *PersonalAccessToken) GetLastUsed() time.Time {
	if o == nil || IsNil(o.LastUsed) {
		var ret time.Time
		return ret
	}
	return *o.LastUsed
}

// GetLastUsedOk returns a tuple with the LastUsed field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *PersonalAccessToken) GetLastUsedOk() (*time.Time, bool) {
	if o == nil || IsNil(o.LastUsed) {
		return nil, false
	}
	return o.LastUsed, true
}

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

	return false
}

// SetLastUsed gets a reference to the given time.Time and assigns it to the LastUsed field.
func (o *PersonalAccessToken) SetLastUsed(v time.Time) {
	o.LastUsed = &v
}

// GetExpirationDate returns the ExpirationDate field value
func (o *PersonalAccessToken) GetExpirationDate() time.Time {
	if o == nil {
		var ret time.Time
		return ret
	}

	return o.ExpirationDate
}

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

// SetExpirationDate sets field value
func (o *PersonalAccessToken) SetExpirationDate(v time.Time) {
	o.ExpirationDate = v
}

// GetCreatedTs returns the CreatedTs field value
func (o *PersonalAccessToken) GetCreatedTs() time.Time {
	if o == nil {
		var ret time.Time
		return ret
	}

	return o.CreatedTs
}

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

// SetCreatedTs sets field value
func (o *PersonalAccessToken) SetCreatedTs(v time.Time) {
	o.CreatedTs = v
}

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

func (o PersonalAccessToken) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["id"] = o.Id
	toSerialize["name"] = o.Name
	if !IsNil(o.LastUsed) {
		toSerialize["last_used"] = o.LastUsed
	}
	toSerialize["expiration_date"] = o.ExpirationDate
	toSerialize["created_ts"] = o.CreatedTs

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

	return toSerialize, nil
}

func (o *PersonalAccessToken) 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",
		"expiration_date",
		"created_ts",
	}

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

	varPersonalAccessToken := _PersonalAccessToken{}

	err = json.Unmarshal(data, &varPersonalAccessToken)

	if err != nil {
		return err
	}

	*o = PersonalAccessToken(varPersonalAccessToken)

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

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

	return err
}

type NullablePersonalAccessToken struct {
	value *PersonalAccessToken
	isSet bool
}

func (v NullablePersonalAccessToken) Get() *PersonalAccessToken {
	return v.value
}

func (v *NullablePersonalAccessToken) Set(val *PersonalAccessToken) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullablePersonalAccessToken(val *PersonalAccessToken) *NullablePersonalAccessToken {
	return &NullablePersonalAccessToken{value: val, isSet: true}
}

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

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


