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

// PreAuthSet struct for PreAuthSet
type PreAuthSet struct {
	// Indicates that despite the device having any authsets the preauthorization should proceed.
	Force *bool `json:"force,omitempty"`
	IdentityData IdentityData `json:"identity_data"`
	// The device's public key (PEM encoding), generated by the device or pre-provisioned by the vendor. Currently supported public algorithms are: RSA, Ed25519 and ECDSA P-256.
	Pubkey string `json:"pubkey"`
	AdditionalProperties map[string]interface{}
}

type _PreAuthSet PreAuthSet

// NewPreAuthSet instantiates a new PreAuthSet 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 NewPreAuthSet(identityData IdentityData, pubkey string) *PreAuthSet {
	this := PreAuthSet{}
	this.IdentityData = identityData
	this.Pubkey = pubkey
	return &this
}

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

// GetForce returns the Force field value if set, zero value otherwise.
func (o *PreAuthSet) GetForce() bool {
	if o == nil || IsNil(o.Force) {
		var ret bool
		return ret
	}
	return *o.Force
}

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

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

	return false
}

// SetForce gets a reference to the given bool and assigns it to the Force field.
func (o *PreAuthSet) SetForce(v bool) {
	o.Force = &v
}

// GetIdentityData returns the IdentityData field value
func (o *PreAuthSet) GetIdentityData() IdentityData {
	if o == nil {
		var ret IdentityData
		return ret
	}

	return o.IdentityData
}

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

// SetIdentityData sets field value
func (o *PreAuthSet) SetIdentityData(v IdentityData) {
	o.IdentityData = v
}

// GetPubkey returns the Pubkey field value
func (o *PreAuthSet) GetPubkey() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Pubkey
}

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

// SetPubkey sets field value
func (o *PreAuthSet) SetPubkey(v string) {
	o.Pubkey = v
}

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

func (o PreAuthSet) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	if !IsNil(o.Force) {
		toSerialize["force"] = o.Force
	}
	toSerialize["identity_data"] = o.IdentityData
	toSerialize["pubkey"] = o.Pubkey

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

	return toSerialize, nil
}

func (o *PreAuthSet) 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{
		"identity_data",
		"pubkey",
	}

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

	varPreAuthSet := _PreAuthSet{}

	err = json.Unmarshal(data, &varPreAuthSet)

	if err != nil {
		return err
	}

	*o = PreAuthSet(varPreAuthSet)

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

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

	return err
}

type NullablePreAuthSet struct {
	value *PreAuthSet
	isSet bool
}

func (v NullablePreAuthSet) Get() *PreAuthSet {
	return v.value
}

func (v *NullablePreAuthSet) Set(val *PreAuthSet) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullablePreAuthSet(val *PreAuthSet) *NullablePreAuthSet {
	return &NullablePreAuthSet{value: val, isSet: true}
}

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

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


