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

# %% auto 0
__all__ = ['DomoPage']

# %% ../../nbs/classes/50_DomoPage.ipynb 2
from fastcore.basics import patch_to

# %% ../../nbs/classes/50_DomoPage.ipynb 3
from dataclasses import dataclass, field

# import asyncio
# import aiohttp

import domolibrary.client.DomoAuth as dmda
import domolibrary.classes.DomoUser as dmdu
import domolibrary.utils.DictDot as util_dd

# from .routes import page_routes
# from ..utils.Base import Base

# %% ../../nbs/classes/50_DomoPage.ipynb 4
@dataclass
class DomoPage:
    id: str
    title: str = None
    parent_page_id: str = None
    auth: dmda.DomoAuth = field(default = None , repr = False)
    owners: list = field(default_factory=list)
    cards: list = field(default_factory=list)
    collections: list = field(default_factory=list)
    children: list = field(default_factory=list)

    def display_url(self):
        return f"https://{self.auth.domo_instance}.domo.com/page/{self.id}"

# %% ../../nbs/classes/50_DomoPage.ipynb 5
@patch_to(DomoPage, cls_method=True)
def _from_bootstrap(cls: DomoPage, page_obj, auth: dmda.DomoAuth = None):

    dd = page_obj
    if isinstance(page_obj, dict):
        dd = util_dd.DictDot(page_obj)

    domo_page = cls(id=dd.id, title=dd.title, auth=auth)

    if isinstance(dd.owners, list) and len(dd.owners) > 0:
        domo_page.owners = [
            dmdu.DomoUser._from_bootstrap_json(auth=auth, user_obj=user_dd)
            for user_dd in dd.owners
            if user_dd.type == 'USER'
        ]

        [print(other_dd) for other_dd in dd.owners
         if other_dd.type != 'USER']

    if isinstance(dd.children, list) and len(dd.children) > 0:
        domo_page.children = [
            cls._from_bootstrap(page_obj=child_dd, auth=auth)
            for child_dd in dd.children
            if child_dd.type == "page"
        ]

        [print(other_dd) for other_dd in dd.children
            if other_dd.type != "page"]

    return domo_page

