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

// UserSelfRoles struct for UserSelfRoles
type UserSelfRoles struct {
	Name                 string `json:"name"`
	Pk                   string `json:"pk"`
	AdditionalProperties map[string]interface{}
}

type _UserSelfRoles UserSelfRoles

// NewUserSelfRoles instantiates a new UserSelfRoles 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 NewUserSelfRoles(name string, pk string) *UserSelfRoles {
	this := UserSelfRoles{}
	this.Name = name
	this.Pk = pk
	return &this
}

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

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

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

// GetPk returns the Pk field value
func (o *UserSelfRoles) GetPk() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Pk
}

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

// SetPk sets field value
func (o *UserSelfRoles) SetPk(v string) {
	o.Pk = v
}

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

func (o UserSelfRoles) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["name"] = o.Name
	toSerialize["pk"] = o.Pk

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

	return toSerialize, nil
}

func (o *UserSelfRoles) 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{
		"name",
		"pk",
	}

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

	varUserSelfRoles := _UserSelfRoles{}

	err = json.Unmarshal(data, &varUserSelfRoles)

	if err != nil {
		return err
	}

	*o = UserSelfRoles(varUserSelfRoles)

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

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

	return err
}

type NullableUserSelfRoles struct {
	value *UserSelfRoles
	isSet bool
}

func (v NullableUserSelfRoles) Get() *UserSelfRoles {
	return v.value
}

func (v *NullableUserSelfRoles) Set(val *UserSelfRoles) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableUserSelfRoles(val *UserSelfRoles) *NullableUserSelfRoles {
	return &NullableUserSelfRoles{value: val, isSet: true}
}

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

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