# coding: utf-8

"""
    authentik

    Making authentication simple.

    The version of the OpenAPI document: 2024.2.2
    Contact: hello@goauthentik.io
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json


from typing import List, Optional, Union
from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, conlist, constr
from authentik_client.models.open_id_connect_configuration import OpenIDConnectConfiguration
from authentik_client.models.proxy_mode import ProxyMode

class ProxyOutpostConfig(BaseModel):
    """
    Proxy provider serializer for outposts  # noqa: E501
    """
    pk: StrictInt = Field(...)
    name: StrictStr = Field(...)
    internal_host: Optional[StrictStr] = None
    external_host: StrictStr = Field(...)
    internal_host_ssl_validation: Optional[StrictBool] = Field(None, description="Validate SSL Certificates of upstream servers")
    client_id: Optional[constr(strict=True, max_length=255)] = None
    client_secret: Optional[constr(strict=True, max_length=255)] = None
    oidc_configuration: OpenIDConnectConfiguration = Field(...)
    cookie_secret: Optional[StrictStr] = None
    certificate: Optional[StrictStr] = None
    skip_path_regex: Optional[StrictStr] = Field(None, description="Regular expressions for which authentication is not required. Each new line is interpreted as a new Regular Expression.")
    basic_auth_enabled: Optional[StrictBool] = Field(None, description="Set a custom HTTP-Basic Authentication header based on values from authentik.")
    basic_auth_password_attribute: Optional[StrictStr] = Field(None, description="User/Group Attribute used for the password part of the HTTP-Basic Header.")
    basic_auth_user_attribute: Optional[StrictStr] = Field(None, description="User/Group Attribute used for the user part of the HTTP-Basic Header. If not set, the user's Email address is used.")
    mode: Optional[ProxyMode] = Field(None, description="Enable support for forwardAuth in traefik and nginx auth_request. Exclusive with internal_host.")
    cookie_domain: Optional[StrictStr] = None
    access_token_validity: Optional[Union[StrictFloat, StrictInt]] = Field(..., description="Get token validity as second count")
    intercept_header_auth: Optional[StrictBool] = Field(None, description="When enabled, this provider will intercept the authorization header and authenticate requests based on its value.")
    scopes_to_request: conlist(StrictStr) = Field(..., description="Get all the scope names the outpost should request, including custom-defined ones")
    assigned_application_slug: StrictStr = Field(..., description="Internal application name, used in URLs.")
    assigned_application_name: StrictStr = Field(..., description="Application's display Name.")
    __properties = ["pk", "name", "internal_host", "external_host", "internal_host_ssl_validation", "client_id", "client_secret", "oidc_configuration", "cookie_secret", "certificate", "skip_path_regex", "basic_auth_enabled", "basic_auth_password_attribute", "basic_auth_user_attribute", "mode", "cookie_domain", "access_token_validity", "intercept_header_auth", "scopes_to_request", "assigned_application_slug", "assigned_application_name"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> ProxyOutpostConfig:
        """Create an instance of ProxyOutpostConfig from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                            "pk",
                            "oidc_configuration",
                            "access_token_validity",
                            "scopes_to_request",
                            "assigned_application_slug",
                            "assigned_application_name",
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of oidc_configuration
        if self.oidc_configuration:
            _dict['oidc_configuration'] = self.oidc_configuration.to_dict()
        # set to None if certificate (nullable) is None
        # and __fields_set__ contains the field
        if self.certificate is None and "certificate" in self.__fields_set__:
            _dict['certificate'] = None

        # set to None if access_token_validity (nullable) is None
        # and __fields_set__ contains the field
        if self.access_token_validity is None and "access_token_validity" in self.__fields_set__:
            _dict['access_token_validity'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> ProxyOutpostConfig:
        """Create an instance of ProxyOutpostConfig from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return ProxyOutpostConfig.parse_obj(obj)

        _obj = ProxyOutpostConfig.parse_obj({
            "pk": obj.get("pk"),
            "name": obj.get("name"),
            "internal_host": obj.get("internal_host"),
            "external_host": obj.get("external_host"),
            "internal_host_ssl_validation": obj.get("internal_host_ssl_validation"),
            "client_id": obj.get("client_id"),
            "client_secret": obj.get("client_secret"),
            "oidc_configuration": OpenIDConnectConfiguration.from_dict(obj.get("oidc_configuration")) if obj.get("oidc_configuration") is not None else None,
            "cookie_secret": obj.get("cookie_secret"),
            "certificate": obj.get("certificate"),
            "skip_path_regex": obj.get("skip_path_regex"),
            "basic_auth_enabled": obj.get("basic_auth_enabled"),
            "basic_auth_password_attribute": obj.get("basic_auth_password_attribute"),
            "basic_auth_user_attribute": obj.get("basic_auth_user_attribute"),
            "mode": obj.get("mode"),
            "cookie_domain": obj.get("cookie_domain"),
            "access_token_validity": obj.get("access_token_validity"),
            "intercept_header_auth": obj.get("intercept_header_auth"),
            "scopes_to_request": obj.get("scopes_to_request"),
            "assigned_application_slug": obj.get("assigned_application_slug"),
            "assigned_application_name": obj.get("assigned_application_name")
        })
        return _obj


