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

// UserSelf User Serializer for information a user can retrieve about themselves
type UserSelf struct {
	Pk int32 `json:"pk"`
	// Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
	Username string `json:"username" validate:"regexp=^[\\\\w.@+-]+$"`
	// User's display name.
	Name string `json:"name"`
	// Designates whether this user should be treated as active. Unselect this instead of deleting accounts.
	IsActive    bool             `json:"is_active"`
	IsSuperuser bool             `json:"is_superuser"`
	Groups      []UserSelfGroups `json:"groups"`
	Roles       []UserSelfRoles  `json:"roles"`
	Email       *string          `json:"email,omitempty"`
	// User's avatar, either a http/https URL or a data URI
	Avatar string `json:"avatar"`
	Uid    string `json:"uid"`
	// Get user settings with brand and group settings applied
	Settings map[string]interface{} `json:"settings"`
	Type     *UserTypeEnum          `json:"type,omitempty"`
	// Get all system permissions assigned to the user
	SystemPermissions    []string `json:"system_permissions"`
	AdditionalProperties map[string]interface{}
}

type _UserSelf UserSelf

// NewUserSelf instantiates a new UserSelf 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 NewUserSelf(pk int32, username string, name string, isActive bool, isSuperuser bool, groups []UserSelfGroups, roles []UserSelfRoles, avatar string, uid string, settings map[string]interface{}, systemPermissions []string) *UserSelf {
	this := UserSelf{}
	this.Pk = pk
	this.Username = username
	this.Name = name
	this.IsActive = isActive
	this.IsSuperuser = isSuperuser
	this.Groups = groups
	this.Roles = roles
	this.Avatar = avatar
	this.Uid = uid
	this.Settings = settings
	this.SystemPermissions = systemPermissions
	return &this
}

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

// GetPk returns the Pk field value
func (o *UserSelf) GetPk() int32 {
	if o == nil {
		var ret int32
		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 *UserSelf) GetPkOk() (*int32, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Pk, true
}

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

// GetUsername returns the Username field value
func (o *UserSelf) GetUsername() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Username
}

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

// SetUsername sets field value
func (o *UserSelf) SetUsername(v string) {
	o.Username = v
}

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

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

// GetIsActive returns the IsActive field value
func (o *UserSelf) GetIsActive() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.IsActive
}

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

// SetIsActive sets field value
func (o *UserSelf) SetIsActive(v bool) {
	o.IsActive = v
}

// GetIsSuperuser returns the IsSuperuser field value
func (o *UserSelf) GetIsSuperuser() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.IsSuperuser
}

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

// SetIsSuperuser sets field value
func (o *UserSelf) SetIsSuperuser(v bool) {
	o.IsSuperuser = v
}

// GetGroups returns the Groups field value
func (o *UserSelf) GetGroups() []UserSelfGroups {
	if o == nil {
		var ret []UserSelfGroups
		return ret
	}

	return o.Groups
}

// GetGroupsOk returns a tuple with the Groups field value
// and a boolean to check if the value has been set.
func (o *UserSelf) GetGroupsOk() ([]UserSelfGroups, bool) {
	if o == nil {
		return nil, false
	}
	return o.Groups, true
}

// SetGroups sets field value
func (o *UserSelf) SetGroups(v []UserSelfGroups) {
	o.Groups = v
}

// GetRoles returns the Roles field value
func (o *UserSelf) GetRoles() []UserSelfRoles {
	if o == nil {
		var ret []UserSelfRoles
		return ret
	}

	return o.Roles
}

// GetRolesOk returns a tuple with the Roles field value
// and a boolean to check if the value has been set.
func (o *UserSelf) GetRolesOk() ([]UserSelfRoles, bool) {
	if o == nil {
		return nil, false
	}
	return o.Roles, true
}

// SetRoles sets field value
func (o *UserSelf) SetRoles(v []UserSelfRoles) {
	o.Roles = v
}

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

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

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

	return false
}

// SetEmail gets a reference to the given string and assigns it to the Email field.
func (o *UserSelf) SetEmail(v string) {
	o.Email = &v
}

// GetAvatar returns the Avatar field value
func (o *UserSelf) GetAvatar() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Avatar
}

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

// SetAvatar sets field value
func (o *UserSelf) SetAvatar(v string) {
	o.Avatar = v
}

// GetUid returns the Uid field value
func (o *UserSelf) GetUid() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Uid
}

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

// SetUid sets field value
func (o *UserSelf) SetUid(v string) {
	o.Uid = v
}

// GetSettings returns the Settings field value
func (o *UserSelf) GetSettings() map[string]interface{} {
	if o == nil {
		var ret map[string]interface{}
		return ret
	}

	return o.Settings
}

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

// SetSettings sets field value
func (o *UserSelf) SetSettings(v map[string]interface{}) {
	o.Settings = v
}

// GetType returns the Type field value if set, zero value otherwise.
func (o *UserSelf) GetType() UserTypeEnum {
	if o == nil || IsNil(o.Type) {
		var ret UserTypeEnum
		return ret
	}
	return *o.Type
}

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

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

	return false
}

// SetType gets a reference to the given UserTypeEnum and assigns it to the Type field.
func (o *UserSelf) SetType(v UserTypeEnum) {
	o.Type = &v
}

// GetSystemPermissions returns the SystemPermissions field value
func (o *UserSelf) GetSystemPermissions() []string {
	if o == nil {
		var ret []string
		return ret
	}

	return o.SystemPermissions
}

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

// SetSystemPermissions sets field value
func (o *UserSelf) SetSystemPermissions(v []string) {
	o.SystemPermissions = v
}

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

func (o UserSelf) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["pk"] = o.Pk
	toSerialize["username"] = o.Username
	toSerialize["name"] = o.Name
	toSerialize["is_active"] = o.IsActive
	toSerialize["is_superuser"] = o.IsSuperuser
	toSerialize["groups"] = o.Groups
	toSerialize["roles"] = o.Roles
	if !IsNil(o.Email) {
		toSerialize["email"] = o.Email
	}
	toSerialize["avatar"] = o.Avatar
	toSerialize["uid"] = o.Uid
	toSerialize["settings"] = o.Settings
	if !IsNil(o.Type) {
		toSerialize["type"] = o.Type
	}
	toSerialize["system_permissions"] = o.SystemPermissions

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

	return toSerialize, nil
}

func (o *UserSelf) 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{
		"pk",
		"username",
		"name",
		"is_active",
		"is_superuser",
		"groups",
		"roles",
		"avatar",
		"uid",
		"settings",
		"system_permissions",
	}

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

	varUserSelf := _UserSelf{}

	err = json.Unmarshal(data, &varUserSelf)

	if err != nil {
		return err
	}

	*o = UserSelf(varUserSelf)

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

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "pk")
		delete(additionalProperties, "username")
		delete(additionalProperties, "name")
		delete(additionalProperties, "is_active")
		delete(additionalProperties, "is_superuser")
		delete(additionalProperties, "groups")
		delete(additionalProperties, "roles")
		delete(additionalProperties, "email")
		delete(additionalProperties, "avatar")
		delete(additionalProperties, "uid")
		delete(additionalProperties, "settings")
		delete(additionalProperties, "type")
		delete(additionalProperties, "system_permissions")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableUserSelf struct {
	value *UserSelf
	isSet bool
}

func (v NullableUserSelf) Get() *UserSelf {
	return v.value
}

func (v *NullableUserSelf) Set(val *UserSelf) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableUserSelf(val *UserSelf) *NullableUserSelf {
	return &NullableUserSelf{value: val, isSet: true}
}

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

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