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

// CertificateKeyPair CertificateKeyPair Serializer
type CertificateKeyPair struct {
	Pk   string `json:"pk"`
	Name string `json:"name"`
	// SHA256 fingerprint of the certificate
	FingerprintSha256 NullableString `json:"fingerprint_sha256"`
	// SHA1 fingerprint of the certificate
	FingerprintSha1 NullableString `json:"fingerprint_sha1"`
	// Certificate expiry date
	CertExpiry NullableTime `json:"cert_expiry"`
	// Certificate subject as RFC4514 string
	CertSubject NullableString `json:"cert_subject"`
	// Show if this keypair has a private key configured or not
	PrivateKeyAvailable bool `json:"private_key_available"`
	// Key algorithm type detected from the certificate's public key
	KeyType NullableCertificateKeyPairKeyTypeEnum `json:"key_type"`
	// Get URL to download certificate
	CertificateDownloadUrl string `json:"certificate_download_url"`
	// Get URL to download private key
	PrivateKeyDownloadUrl string `json:"private_key_download_url"`
	// Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.
	Managed              NullableString `json:"managed"`
	AdditionalProperties map[string]interface{}
}

type _CertificateKeyPair CertificateKeyPair

// NewCertificateKeyPair instantiates a new CertificateKeyPair 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 NewCertificateKeyPair(pk string, name string, fingerprintSha256 NullableString, fingerprintSha1 NullableString, certExpiry NullableTime, certSubject NullableString, privateKeyAvailable bool, keyType NullableCertificateKeyPairKeyTypeEnum, certificateDownloadUrl string, privateKeyDownloadUrl string, managed NullableString) *CertificateKeyPair {
	this := CertificateKeyPair{}
	this.Pk = pk
	this.Name = name
	this.FingerprintSha256 = fingerprintSha256
	this.FingerprintSha1 = fingerprintSha1
	this.CertExpiry = certExpiry
	this.CertSubject = certSubject
	this.PrivateKeyAvailable = privateKeyAvailable
	this.KeyType = keyType
	this.CertificateDownloadUrl = certificateDownloadUrl
	this.PrivateKeyDownloadUrl = privateKeyDownloadUrl
	this.Managed = managed
	return &this
}

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

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

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

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

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

// GetFingerprintSha256 returns the FingerprintSha256 field value
// If the value is explicit nil, the zero value for string will be returned
func (o *CertificateKeyPair) GetFingerprintSha256() string {
	if o == nil || o.FingerprintSha256.Get() == nil {
		var ret string
		return ret
	}

	return *o.FingerprintSha256.Get()
}

// GetFingerprintSha256Ok returns a tuple with the FingerprintSha256 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 *CertificateKeyPair) GetFingerprintSha256Ok() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return o.FingerprintSha256.Get(), o.FingerprintSha256.IsSet()
}

// SetFingerprintSha256 sets field value
func (o *CertificateKeyPair) SetFingerprintSha256(v string) {
	o.FingerprintSha256.Set(&v)
}

// GetFingerprintSha1 returns the FingerprintSha1 field value
// If the value is explicit nil, the zero value for string will be returned
func (o *CertificateKeyPair) GetFingerprintSha1() string {
	if o == nil || o.FingerprintSha1.Get() == nil {
		var ret string
		return ret
	}

	return *o.FingerprintSha1.Get()
}

// GetFingerprintSha1Ok returns a tuple with the FingerprintSha1 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 *CertificateKeyPair) GetFingerprintSha1Ok() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return o.FingerprintSha1.Get(), o.FingerprintSha1.IsSet()
}

// SetFingerprintSha1 sets field value
func (o *CertificateKeyPair) SetFingerprintSha1(v string) {
	o.FingerprintSha1.Set(&v)
}

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

	return *o.CertExpiry.Get()
}

// GetCertExpiryOk returns a tuple with the CertExpiry 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 *CertificateKeyPair) GetCertExpiryOk() (*time.Time, bool) {
	if o == nil {
		return nil, false
	}
	return o.CertExpiry.Get(), o.CertExpiry.IsSet()
}

// SetCertExpiry sets field value
func (o *CertificateKeyPair) SetCertExpiry(v time.Time) {
	o.CertExpiry.Set(&v)
}

// GetCertSubject returns the CertSubject field value
// If the value is explicit nil, the zero value for string will be returned
func (o *CertificateKeyPair) GetCertSubject() string {
	if o == nil || o.CertSubject.Get() == nil {
		var ret string
		return ret
	}

	return *o.CertSubject.Get()
}

// GetCertSubjectOk returns a tuple with the CertSubject 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 *CertificateKeyPair) GetCertSubjectOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return o.CertSubject.Get(), o.CertSubject.IsSet()
}

// SetCertSubject sets field value
func (o *CertificateKeyPair) SetCertSubject(v string) {
	o.CertSubject.Set(&v)
}

// GetPrivateKeyAvailable returns the PrivateKeyAvailable field value
func (o *CertificateKeyPair) GetPrivateKeyAvailable() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.PrivateKeyAvailable
}

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

// SetPrivateKeyAvailable sets field value
func (o *CertificateKeyPair) SetPrivateKeyAvailable(v bool) {
	o.PrivateKeyAvailable = v
}

// GetKeyType returns the KeyType field value
// If the value is explicit nil, the zero value for CertificateKeyPairKeyTypeEnum will be returned
func (o *CertificateKeyPair) GetKeyType() CertificateKeyPairKeyTypeEnum {
	if o == nil || o.KeyType.Get() == nil {
		var ret CertificateKeyPairKeyTypeEnum
		return ret
	}

	return *o.KeyType.Get()
}

// GetKeyTypeOk returns a tuple with the KeyType 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 *CertificateKeyPair) GetKeyTypeOk() (*CertificateKeyPairKeyTypeEnum, bool) {
	if o == nil {
		return nil, false
	}
	return o.KeyType.Get(), o.KeyType.IsSet()
}

// SetKeyType sets field value
func (o *CertificateKeyPair) SetKeyType(v CertificateKeyPairKeyTypeEnum) {
	o.KeyType.Set(&v)
}

// GetCertificateDownloadUrl returns the CertificateDownloadUrl field value
func (o *CertificateKeyPair) GetCertificateDownloadUrl() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.CertificateDownloadUrl
}

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

// SetCertificateDownloadUrl sets field value
func (o *CertificateKeyPair) SetCertificateDownloadUrl(v string) {
	o.CertificateDownloadUrl = v
}

// GetPrivateKeyDownloadUrl returns the PrivateKeyDownloadUrl field value
func (o *CertificateKeyPair) GetPrivateKeyDownloadUrl() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.PrivateKeyDownloadUrl
}

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

// SetPrivateKeyDownloadUrl sets field value
func (o *CertificateKeyPair) SetPrivateKeyDownloadUrl(v string) {
	o.PrivateKeyDownloadUrl = v
}

// GetManaged returns the Managed field value
// If the value is explicit nil, the zero value for string will be returned
func (o *CertificateKeyPair) GetManaged() string {
	if o == nil || o.Managed.Get() == nil {
		var ret string
		return ret
	}

	return *o.Managed.Get()
}

// GetManagedOk returns a tuple with the Managed 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 *CertificateKeyPair) GetManagedOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return o.Managed.Get(), o.Managed.IsSet()
}

// SetManaged sets field value
func (o *CertificateKeyPair) SetManaged(v string) {
	o.Managed.Set(&v)
}

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

func (o CertificateKeyPair) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["pk"] = o.Pk
	toSerialize["name"] = o.Name
	toSerialize["fingerprint_sha256"] = o.FingerprintSha256.Get()
	toSerialize["fingerprint_sha1"] = o.FingerprintSha1.Get()
	toSerialize["cert_expiry"] = o.CertExpiry.Get()
	toSerialize["cert_subject"] = o.CertSubject.Get()
	toSerialize["private_key_available"] = o.PrivateKeyAvailable
	toSerialize["key_type"] = o.KeyType.Get()
	toSerialize["certificate_download_url"] = o.CertificateDownloadUrl
	toSerialize["private_key_download_url"] = o.PrivateKeyDownloadUrl
	toSerialize["managed"] = o.Managed.Get()

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

	return toSerialize, nil
}

func (o *CertificateKeyPair) 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",
		"name",
		"fingerprint_sha256",
		"fingerprint_sha1",
		"cert_expiry",
		"cert_subject",
		"private_key_available",
		"key_type",
		"certificate_download_url",
		"private_key_download_url",
		"managed",
	}

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

	varCertificateKeyPair := _CertificateKeyPair{}

	err = json.Unmarshal(data, &varCertificateKeyPair)

	if err != nil {
		return err
	}

	*o = CertificateKeyPair(varCertificateKeyPair)

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

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "pk")
		delete(additionalProperties, "name")
		delete(additionalProperties, "fingerprint_sha256")
		delete(additionalProperties, "fingerprint_sha1")
		delete(additionalProperties, "cert_expiry")
		delete(additionalProperties, "cert_subject")
		delete(additionalProperties, "private_key_available")
		delete(additionalProperties, "key_type")
		delete(additionalProperties, "certificate_download_url")
		delete(additionalProperties, "private_key_download_url")
		delete(additionalProperties, "managed")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableCertificateKeyPair struct {
	value *CertificateKeyPair
	isSet bool
}

func (v NullableCertificateKeyPair) Get() *CertificateKeyPair {
	return v.value
}

func (v *NullableCertificateKeyPair) Set(val *CertificateKeyPair) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableCertificateKeyPair(val *CertificateKeyPair) *NullableCertificateKeyPair {
	return &NullableCertificateKeyPair{value: val, isSet: true}
}

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

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