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

# %% ../../nbs/classes/50_DomoDataflow_Action.ipynb 2
from __future__ import annotations

from enum import Enum
from dataclasses import dataclass

import datetime as dt
import domolibrary.utils.DictDot as util_dd

# %% auto 0
__all__ = ['DomoDataflow_Action_Type', 'DomoDataflow_Action', 'DomoDataflow_ActionResult']

# %% ../../nbs/classes/50_DomoDataflow_Action.ipynb 4
class DomoDataflow_Action_Type(Enum):
    LoadFromVault = "LoadFromVault"
    PublishToVault = "PublishToVault"
    GenerateTableAction = "GenerateTableAction"


@dataclass
class DomoDataflow_Action:
    id: str

    type: str = None
    depends_on : str = None
    name: str = None
    
    datasource_id: str  = None
    sql: str = None


    @classmethod
    def _from_json(cls, obj: dict):
        dd = obj

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

        tbl_name = dd.dataSource.name if dd.dataSource else None
        ds_id = dd.dataSource.guid if dd.dataSource else None

        return  cls(
            type=dd.type,
            id=dd.id,
            name=dd.name or dd.targetTableName or dd.tableName or tbl_name,
            depends_on = dd.dependsOn,
            
            datasource_id=dd.dataSourceId or ds_id,
            sql=dd.selectStatement or dd.query,
        )



# %% ../../nbs/classes/50_DomoDataflow_Action.ipynb 7
@dataclass
class DomoDataflow_ActionResult(DomoDataflow_Action):
    is_success : bool = None
    rows_processed : int = None
    begin_time : dt.datetime = None
    end_time : dt.datetime = None

    @classmethod
    def _from_json(cls, obj: dict):
        return  cls(
            id=obj.get('actionId'),
            type = obj.get('type'),
            is_success = obj.get('wasSuccessful'),
            begin_time = obj.get('beginTime', None),
            end_time = obj.get('endTime', None),
            rows_processed =  obj.get('rowsProcessed', None),
        )

