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

// User User descriptor.
type User struct {
	// A unique email address.
	Email string `json:"email"`
	// User Id.
	Id string `json:"id"`
	// Server-side timestamp of the user creation. 
	CreatedTs *time.Time `json:"created_ts,omitempty"`
	// Server-side timestamp of the last user information update. 
	UpdatedTs *time.Time `json:"updated_ts,omitempty"`
	// Timestamp of last successful login.
	LoginTs *time.Time `json:"login_ts,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _User User

// NewUser instantiates a new User 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 NewUser(email string, id string) *User {
	this := User{}
	this.Email = email
	this.Id = id
	return &this
}

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

// GetEmail returns the Email field value
func (o *User) GetEmail() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Email
}

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

// SetEmail sets field value
func (o *User) SetEmail(v string) {
	o.Email = v
}

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

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

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

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

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

	return false
}

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

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

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

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

	return false
}

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

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

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

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

	return false
}

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

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

func (o User) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["email"] = o.Email
	toSerialize["id"] = o.Id
	if !IsNil(o.CreatedTs) {
		toSerialize["created_ts"] = o.CreatedTs
	}
	if !IsNil(o.UpdatedTs) {
		toSerialize["updated_ts"] = o.UpdatedTs
	}
	if !IsNil(o.LoginTs) {
		toSerialize["login_ts"] = o.LoginTs
	}

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

	return toSerialize, nil
}

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

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

	varUser := _User{}

	err = json.Unmarshal(data, &varUser)

	if err != nil {
		return err
	}

	*o = User(varUser)

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

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "email")
		delete(additionalProperties, "id")
		delete(additionalProperties, "created_ts")
		delete(additionalProperties, "updated_ts")
		delete(additionalProperties, "login_ts")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableUser struct {
	value *User
	isSet bool
}

func (v NullableUser) Get() *User {
	return v.value
}

func (v *NullableUser) Set(val *User) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableUser(val *User) *NullableUser {
	return &NullableUser{value: val, isSet: true}
}

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

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


