/*
authentik

Making authentication simple.

API version: 2026.5.0-rc1
Contact: hello@goauthentik.io
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package api

import (
	"encoding/json"
	"fmt"
)

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

// AuthenticatorTOTPChallengeResponseRequest TOTP Challenge response, device is set by get_response_instance
type AuthenticatorTOTPChallengeResponseRequest struct {
	Component            *string `json:"component,omitempty"`
	Code                 string  `json:"code"`
	AdditionalProperties map[string]interface{}
}

type _AuthenticatorTOTPChallengeResponseRequest AuthenticatorTOTPChallengeResponseRequest

// NewAuthenticatorTOTPChallengeResponseRequest instantiates a new AuthenticatorTOTPChallengeResponseRequest 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 NewAuthenticatorTOTPChallengeResponseRequest(code string) *AuthenticatorTOTPChallengeResponseRequest {
	this := AuthenticatorTOTPChallengeResponseRequest{}
	var component string = "ak-stage-authenticator-totp"
	this.Component = &component
	this.Code = code
	return &this
}

// NewAuthenticatorTOTPChallengeResponseRequestWithDefaults instantiates a new AuthenticatorTOTPChallengeResponseRequest 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 NewAuthenticatorTOTPChallengeResponseRequestWithDefaults() *AuthenticatorTOTPChallengeResponseRequest {
	this := AuthenticatorTOTPChallengeResponseRequest{}
	var component string = "ak-stage-authenticator-totp"
	this.Component = &component
	return &this
}

// GetComponent returns the Component field value if set, zero value otherwise.
func (o *AuthenticatorTOTPChallengeResponseRequest) GetComponent() string {
	if o == nil || IsNil(o.Component) {
		var ret string
		return ret
	}
	return *o.Component
}

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

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

	return false
}

// SetComponent gets a reference to the given string and assigns it to the Component field.
func (o *AuthenticatorTOTPChallengeResponseRequest) SetComponent(v string) {
	o.Component = &v
}

// GetCode returns the Code field value
func (o *AuthenticatorTOTPChallengeResponseRequest) GetCode() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Code
}

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

// SetCode sets field value
func (o *AuthenticatorTOTPChallengeResponseRequest) SetCode(v string) {
	o.Code = v
}

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

func (o AuthenticatorTOTPChallengeResponseRequest) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	if !IsNil(o.Component) {
		toSerialize["component"] = o.Component
	}
	toSerialize["code"] = o.Code

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

	return toSerialize, nil
}

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

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

	varAuthenticatorTOTPChallengeResponseRequest := _AuthenticatorTOTPChallengeResponseRequest{}

	err = json.Unmarshal(data, &varAuthenticatorTOTPChallengeResponseRequest)

	if err != nil {
		return err
	}

	*o = AuthenticatorTOTPChallengeResponseRequest(varAuthenticatorTOTPChallengeResponseRequest)

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

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

	return err
}

type NullableAuthenticatorTOTPChallengeResponseRequest struct {
	value *AuthenticatorTOTPChallengeResponseRequest
	isSet bool
}

func (v NullableAuthenticatorTOTPChallengeResponseRequest) Get() *AuthenticatorTOTPChallengeResponseRequest {
	return v.value
}

func (v *NullableAuthenticatorTOTPChallengeResponseRequest) Set(val *AuthenticatorTOTPChallengeResponseRequest) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableAuthenticatorTOTPChallengeResponseRequest(val *AuthenticatorTOTPChallengeResponseRequest) *NullableAuthenticatorTOTPChallengeResponseRequest {
	return &NullableAuthenticatorTOTPChallengeResponseRequest{value: val, isSet: true}
}

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

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