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

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

// DeviceChallengeRequest Single device challenge
type DeviceChallengeRequest struct {
	DeviceClass          DeviceClassesEnum      `json:"device_class"`
	DeviceUid            string                 `json:"device_uid"`
	Challenge            map[string]interface{} `json:"challenge"`
	LastUsed             NullableTime           `json:"last_used"`
	AdditionalProperties map[string]interface{}
}

type _DeviceChallengeRequest DeviceChallengeRequest

// NewDeviceChallengeRequest instantiates a new DeviceChallengeRequest 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 NewDeviceChallengeRequest(deviceClass DeviceClassesEnum, deviceUid string, challenge map[string]interface{}, lastUsed NullableTime) *DeviceChallengeRequest {
	this := DeviceChallengeRequest{}
	this.DeviceClass = deviceClass
	this.DeviceUid = deviceUid
	this.Challenge = challenge
	this.LastUsed = lastUsed
	return &this
}

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

// GetDeviceClass returns the DeviceClass field value
func (o *DeviceChallengeRequest) GetDeviceClass() DeviceClassesEnum {
	if o == nil {
		var ret DeviceClassesEnum
		return ret
	}

	return o.DeviceClass
}

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

// SetDeviceClass sets field value
func (o *DeviceChallengeRequest) SetDeviceClass(v DeviceClassesEnum) {
	o.DeviceClass = v
}

// GetDeviceUid returns the DeviceUid field value
func (o *DeviceChallengeRequest) GetDeviceUid() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.DeviceUid
}

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

// SetDeviceUid sets field value
func (o *DeviceChallengeRequest) SetDeviceUid(v string) {
	o.DeviceUid = v
}

// GetChallenge returns the Challenge field value
func (o *DeviceChallengeRequest) GetChallenge() map[string]interface{} {
	if o == nil {
		var ret map[string]interface{}
		return ret
	}

	return o.Challenge
}

// GetChallengeOk returns a tuple with the Challenge field value
// and a boolean to check if the value has been set.
func (o *DeviceChallengeRequest) GetChallengeOk() (map[string]interface{}, bool) {
	if o == nil {
		return map[string]interface{}{}, false
	}
	return o.Challenge, true
}

// SetChallenge sets field value
func (o *DeviceChallengeRequest) SetChallenge(v map[string]interface{}) {
	o.Challenge = v
}

// GetLastUsed returns the LastUsed field value
// If the value is explicit nil, the zero value for time.Time will be returned
func (o *DeviceChallengeRequest) GetLastUsed() time.Time {
	if o == nil || o.LastUsed.Get() == nil {
		var ret time.Time
		return ret
	}

	return *o.LastUsed.Get()
}

// GetLastUsedOk returns a tuple with the LastUsed field value
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *DeviceChallengeRequest) GetLastUsedOk() (*time.Time, bool) {
	if o == nil {
		return nil, false
	}
	return o.LastUsed.Get(), o.LastUsed.IsSet()
}

// SetLastUsed sets field value
func (o *DeviceChallengeRequest) SetLastUsed(v time.Time) {
	o.LastUsed.Set(&v)
}

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

func (o DeviceChallengeRequest) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["device_class"] = o.DeviceClass
	toSerialize["device_uid"] = o.DeviceUid
	toSerialize["challenge"] = o.Challenge
	toSerialize["last_used"] = o.LastUsed.Get()

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

	return toSerialize, nil
}

func (o *DeviceChallengeRequest) 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{
		"device_class",
		"device_uid",
		"challenge",
		"last_used",
	}

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

	varDeviceChallengeRequest := _DeviceChallengeRequest{}

	err = json.Unmarshal(data, &varDeviceChallengeRequest)

	if err != nil {
		return err
	}

	*o = DeviceChallengeRequest(varDeviceChallengeRequest)

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

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "device_class")
		delete(additionalProperties, "device_uid")
		delete(additionalProperties, "challenge")
		delete(additionalProperties, "last_used")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableDeviceChallengeRequest struct {
	value *DeviceChallengeRequest
	isSet bool
}

func (v NullableDeviceChallengeRequest) Get() *DeviceChallengeRequest {
	return v.value
}

func (v *NullableDeviceChallengeRequest) Set(val *DeviceChallengeRequest) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableDeviceChallengeRequest(val *DeviceChallengeRequest) *NullableDeviceChallengeRequest {
	return &NullableDeviceChallengeRequest{value: val, isSet: true}
}

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

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