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

// User User Serializer
type User struct {
	Pk       int32  `json:"pk"`
	Username string `json:"username"`
	// 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,omitempty"`
	LastLogin   NullableTime   `json:"last_login,omitempty"`
	DateJoined  time.Time      `json:"date_joined"`
	IsSuperuser bool           `json:"is_superuser"`
	Groups      []string       `json:"groups,omitempty"`
	GroupsObj   []PartialGroup `json:"groups_obj"`
	Roles       []string       `json:"roles,omitempty"`
	RolesObj    []Role         `json:"roles_obj"`
	Email       *string        `json:"email,omitempty"`
	// User's avatar, either a http/https URL or a data URI
	Avatar               string                 `json:"avatar"`
	Attributes           map[string]interface{} `json:"attributes,omitempty"`
	Uid                  string                 `json:"uid"`
	Path                 *string                `json:"path,omitempty"`
	Type                 *UserTypeEnum          `json:"type,omitempty"`
	Uuid                 string                 `json:"uuid"`
	PasswordChangeDate   time.Time              `json:"password_change_date"`
	LastUpdated          time.Time              `json:"last_updated"`
	AdditionalProperties map[string]interface{}
}

type _User User

// NewUser instantiates a new User 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 NewUser(pk int32, username string, name string, dateJoined time.Time, isSuperuser bool, groupsObj []PartialGroup, rolesObj []Role, avatar string, uid string, uuid string, passwordChangeDate time.Time, lastUpdated time.Time) *User {
	this := User{}
	this.Pk = pk
	this.Username = username
	this.Name = name
	this.DateJoined = dateJoined
	this.IsSuperuser = isSuperuser
	this.GroupsObj = groupsObj
	this.RolesObj = rolesObj
	this.Avatar = avatar
	this.Uid = uid
	this.Uuid = uuid
	this.PasswordChangeDate = passwordChangeDate
	this.LastUpdated = lastUpdated
	return &this
}

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

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

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

// GetUsername returns the Username field value
func (o *User) 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 *User) GetUsernameOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Username, true
}

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

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

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

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

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

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

	return false
}

// SetIsActive gets a reference to the given bool and assigns it to the IsActive field.
func (o *User) SetIsActive(v bool) {
	o.IsActive = &v
}

// GetLastLogin returns the LastLogin field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *User) GetLastLogin() time.Time {
	if o == nil || IsNil(o.LastLogin.Get()) {
		var ret time.Time
		return ret
	}
	return *o.LastLogin.Get()
}

// GetLastLoginOk returns a tuple with the LastLogin field value if set, nil otherwise
// 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 *User) GetLastLoginOk() (*time.Time, bool) {
	if o == nil {
		return nil, false
	}
	return o.LastLogin.Get(), o.LastLogin.IsSet()
}

// HasLastLogin returns a boolean if a field has been set.
func (o *User) HasLastLogin() bool {
	if o != nil && o.LastLogin.IsSet() {
		return true
	}

	return false
}

// SetLastLogin gets a reference to the given NullableTime and assigns it to the LastLogin field.
func (o *User) SetLastLogin(v time.Time) {
	o.LastLogin.Set(&v)
}

// SetLastLoginNil sets the value for LastLogin to be an explicit nil
func (o *User) SetLastLoginNil() {
	o.LastLogin.Set(nil)
}

// UnsetLastLogin ensures that no value is present for LastLogin, not even an explicit nil
func (o *User) UnsetLastLogin() {
	o.LastLogin.Unset()
}

// GetDateJoined returns the DateJoined field value
func (o *User) GetDateJoined() time.Time {
	if o == nil {
		var ret time.Time
		return ret
	}

	return o.DateJoined
}

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

// SetDateJoined sets field value
func (o *User) SetDateJoined(v time.Time) {
	o.DateJoined = v
}

// GetIsSuperuser returns the IsSuperuser field value
func (o *User) 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 *User) GetIsSuperuserOk() (*bool, bool) {
	if o == nil {
		return nil, false
	}
	return &o.IsSuperuser, true
}

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

// GetGroups returns the Groups field value if set, zero value otherwise.
func (o *User) GetGroups() []string {
	if o == nil || IsNil(o.Groups) {
		var ret []string
		return ret
	}
	return o.Groups
}

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

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

	return false
}

// SetGroups gets a reference to the given []string and assigns it to the Groups field.
func (o *User) SetGroups(v []string) {
	o.Groups = v
}

// GetGroupsObj returns the GroupsObj field value
// If the value is explicit nil, the zero value for []PartialGroup will be returned
func (o *User) GetGroupsObj() []PartialGroup {
	if o == nil {
		var ret []PartialGroup
		return ret
	}

	return o.GroupsObj
}

// GetGroupsObjOk returns a tuple with the GroupsObj 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 *User) GetGroupsObjOk() ([]PartialGroup, bool) {
	if o == nil || IsNil(o.GroupsObj) {
		return nil, false
	}
	return o.GroupsObj, true
}

// SetGroupsObj sets field value
func (o *User) SetGroupsObj(v []PartialGroup) {
	o.GroupsObj = v
}

// GetRoles returns the Roles field value if set, zero value otherwise.
func (o *User) GetRoles() []string {
	if o == nil || IsNil(o.Roles) {
		var ret []string
		return ret
	}
	return o.Roles
}

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

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

	return false
}

// SetRoles gets a reference to the given []string and assigns it to the Roles field.
func (o *User) SetRoles(v []string) {
	o.Roles = v
}

// GetRolesObj returns the RolesObj field value
// If the value is explicit nil, the zero value for []Role will be returned
func (o *User) GetRolesObj() []Role {
	if o == nil {
		var ret []Role
		return ret
	}

	return o.RolesObj
}

// GetRolesObjOk returns a tuple with the RolesObj 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 *User) GetRolesObjOk() ([]Role, bool) {
	if o == nil || IsNil(o.RolesObj) {
		return nil, false
	}
	return o.RolesObj, true
}

// SetRolesObj sets field value
func (o *User) SetRolesObj(v []Role) {
	o.RolesObj = v
}

// GetEmail returns the Email field value if set, zero value otherwise.
func (o *User) 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 *User) 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 *User) 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 *User) SetEmail(v string) {
	o.Email = &v
}

// GetAvatar returns the Avatar field value
func (o *User) 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 *User) GetAvatarOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Avatar, true
}

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

// GetAttributes returns the Attributes field value if set, zero value otherwise.
func (o *User) GetAttributes() map[string]interface{} {
	if o == nil || IsNil(o.Attributes) {
		var ret map[string]interface{}
		return ret
	}
	return o.Attributes
}

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

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

	return false
}

// SetAttributes gets a reference to the given map[string]interface{} and assigns it to the Attributes field.
func (o *User) SetAttributes(v map[string]interface{}) {
	o.Attributes = v
}

// GetUid returns the Uid field value
func (o *User) 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 *User) GetUidOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Uid, true
}

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

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

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

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

	return false
}

// SetPath gets a reference to the given string and assigns it to the Path field.
func (o *User) SetPath(v string) {
	o.Path = &v
}

// GetType returns the Type field value if set, zero value otherwise.
func (o *User) 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 *User) 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 *User) 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 *User) SetType(v UserTypeEnum) {
	o.Type = &v
}

// GetUuid returns the Uuid field value
func (o *User) GetUuid() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Uuid
}

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

// SetUuid sets field value
func (o *User) SetUuid(v string) {
	o.Uuid = v
}

// GetPasswordChangeDate returns the PasswordChangeDate field value
func (o *User) GetPasswordChangeDate() time.Time {
	if o == nil {
		var ret time.Time
		return ret
	}

	return o.PasswordChangeDate
}

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

// SetPasswordChangeDate sets field value
func (o *User) SetPasswordChangeDate(v time.Time) {
	o.PasswordChangeDate = v
}

// GetLastUpdated returns the LastUpdated field value
func (o *User) GetLastUpdated() time.Time {
	if o == nil {
		var ret time.Time
		return ret
	}

	return o.LastUpdated
}

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

// SetLastUpdated sets field value
func (o *User) SetLastUpdated(v time.Time) {
	o.LastUpdated = v
}

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

func (o User) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["pk"] = o.Pk
	toSerialize["username"] = o.Username
	toSerialize["name"] = o.Name
	if !IsNil(o.IsActive) {
		toSerialize["is_active"] = o.IsActive
	}
	if o.LastLogin.IsSet() {
		toSerialize["last_login"] = o.LastLogin.Get()
	}
	toSerialize["date_joined"] = o.DateJoined
	toSerialize["is_superuser"] = o.IsSuperuser
	if !IsNil(o.Groups) {
		toSerialize["groups"] = o.Groups
	}
	if o.GroupsObj != nil {
		toSerialize["groups_obj"] = o.GroupsObj
	}
	if !IsNil(o.Roles) {
		toSerialize["roles"] = o.Roles
	}
	if o.RolesObj != nil {
		toSerialize["roles_obj"] = o.RolesObj
	}
	if !IsNil(o.Email) {
		toSerialize["email"] = o.Email
	}
	toSerialize["avatar"] = o.Avatar
	if !IsNil(o.Attributes) {
		toSerialize["attributes"] = o.Attributes
	}
	toSerialize["uid"] = o.Uid
	if !IsNil(o.Path) {
		toSerialize["path"] = o.Path
	}
	if !IsNil(o.Type) {
		toSerialize["type"] = o.Type
	}
	toSerialize["uuid"] = o.Uuid
	toSerialize["password_change_date"] = o.PasswordChangeDate
	toSerialize["last_updated"] = o.LastUpdated

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

	return toSerialize, nil
}

func (o *User) 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",
		"date_joined",
		"is_superuser",
		"groups_obj",
		"roles_obj",
		"avatar",
		"uid",
		"uuid",
		"password_change_date",
		"last_updated",
	}

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

	varUser := _User{}

	err = json.Unmarshal(data, &varUser)

	if err != nil {
		return err
	}

	*o = User(varUser)

	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, "last_login")
		delete(additionalProperties, "date_joined")
		delete(additionalProperties, "is_superuser")
		delete(additionalProperties, "groups")
		delete(additionalProperties, "groups_obj")
		delete(additionalProperties, "roles")
		delete(additionalProperties, "roles_obj")
		delete(additionalProperties, "email")
		delete(additionalProperties, "avatar")
		delete(additionalProperties, "attributes")
		delete(additionalProperties, "uid")
		delete(additionalProperties, "path")
		delete(additionalProperties, "type")
		delete(additionalProperties, "uuid")
		delete(additionalProperties, "password_change_date")
		delete(additionalProperties, "last_updated")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableUser struct {
	value *User
	isSet bool
}

func (v NullableUser) Get() *User {
	return v.value
}

func (v *NullableUser) Set(val *User) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableUser(val *User) *NullableUser {
	return &NullableUser{value: val, isSet: true}
}

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

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