# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/classes/50_DomoInsanceConfig_SSO.ipynb.

# %% auto 0
__all__ = ['SSOConfig_InstantiationError', 'SSO_Config', 'SSO_OIDC_Config']

# %% ../../nbs/classes/50_DomoInsanceConfig_SSO.ipynb 2
import httpx
import datetime as dt
from nbdev.showdoc import patch_to
import sys
import pandas as pd


from dataclasses import dataclass, field, asdict
import domolibrary.client.DomoAuth as dmda
import domolibrary.client.DomoError as dmde

import domolibrary.routes.sso as sso_routes


# import domolibrary.utils.DictDot as util_dd
# import domolibrary.utils.chunk_execution as ce
# import domolibrary.utils.convert as cd



# %% ../../nbs/classes/50_DomoInsanceConfig_SSO.ipynb 6
py310 = sys.version_info.minor >= 10 or sys.version_info.major > 3

# %% ../../nbs/classes/50_DomoInsanceConfig_SSO.ipynb 7
class SSOConfig_InstantiationError(dmde.DomoError):
    def __init__(self, message, auth, parent_class = None):

        super().__init__(
            domo_instance=auth.domo_instance,
            message=message,
            parent_class=parent_class)


@dataclass
class SSO_Config:
    auth: dmda.DomoAuth = field(repr=False)
    
    @classmethod
    def _from_json(cls, auth: dmda.DomoAuth, obj: dict):

        return cls(
            auth=auth,
            **obj
        )

    def add_attribute(self,
                      **kwargs):
        
        for key, value in kwargs.items():
            if not hasattr(self, key):
                raise SSOConfig_InstantiationError( f"key {key} not part of OIDC config", auth = self.auth)
            if value is not None: 
                setattr(self, key, value)
            
        return self


@dataclass(**({"slots": True} if py310 else {}))

class SSO_OIDC_Config(SSO_Config):

    login_enabled :bool = None
    idp_enabled : bool = None
    import_groups : bool = None
    require_invitation : bool = None
    enforce_allowlist : bool = None
    skip_to_idp : bool = None
    auth_request_endpoint : str = None # url
    token_endpoint = None
    user_info_endpoint = None
    public_key = None
    redirect_url : str = None # url
    idp_certificate : str = None
    override_sso = None
    override_embed =None
    well_known_config = None
    assertion_endpoint = None
    ingest_attributes = None


    def to_json(self, is_include_undefined: bool = False):
        obj = asdict(self)
        obj.pop('auth')

        return sso_routes.generate_sso_oidc_body( **obj,
                                          is_include_undefined = is_include_undefined)

        
