import json
from typing import List, Dict

from pilot.pojo.request.bury_Message import BuryMessage


class CommonAttributeRequest:
    def __init__(self, userName="",
                 needAddDimension=True,
                 attributeSessionId="",
                 enterType=0,
                 subjectId="0",
                 row=None,
                 column=None,
                 magnanimity=None,
                 filter=None,
                 stepList=None,
                 dimensionJson=None,
                 buryMessage=None,
                 analysisId=0,
                 attriMagnanimity="",
                 crossRow=None,
                 **kwargs):
        self.user_name: str = userName
        # 是否需要补充维度
        self.need_add_dimension: bool = needAddDimension
        self.attribute_session_id: str = attributeSessionId
        # 入口 1：任务列表界面，2：小助手自动触发，3：整列数据触发，4：查询页面单个单元格
        self.enter_type: int = enterType
        self.subject_id: str = subjectId

        self.row: List = row if row else []
        self.column: List = column if column else []
        self.magnanimity: List = magnanimity if magnanimity else []
        self.filter: List = filter if filter else []
        self.stepList: List = stepList if stepList else []
        self.dimensionJson: Dict = dimensionJson if dimensionJson else {}
        self.buryMessage: BuryMessage = BuryMessage(**buryMessage) if buryMessage else BuryMessage()
        # 埋点用户的分析url的id
        self.analysisId: int = analysisId
        # 用户选定的一个归因指标
        self.attriMagnanimity: str = attriMagnanimity
        self.crossRow:List = crossRow if crossRow else []
        self.verify_param()

    def verify_param(self):
        assert self.user_name, "userName should not None"
        assert self.enter_type in [1, 2, 3, 4], "enterType not in [1,2,3,4]"
        assert self.subject_id, "subjectId is empty"
        assert self.row or self.column, "row and column can not be empty at same time"
        assert self.magnanimity, "magnanimity is empty"
        assert self.filter, "filter is empty"
        # 如果存在，一定要符合类型
        assert not self.stepList or isinstance(self.stepList, list), "stepList should be list"
        assert not self.dimensionJson or isinstance(self.dimensionJson, dict), "dimensionJson should be map"
        # 如果归因指标存在，则一定可以转换成整数
        assert self.attriMagnanimity, "attriMagnanimity is empty"
        assert isinstance(self.crossRow, list), "crossRow should be list"

    def __repr__(self):
        return f"CommonAttributeRequest({self.__dict__})"


if __name__ == '__main__':
    aa = '{"userName":"xxxx","attributeSessionId":"xxx","enterType":1,"subjectId":"3","row":["1562","333"],"column":["1274"],"magnanimity":[{"id":"8000367","name":"vipvma_ads_order_goods_new_analysis_hm.avg_amt_day","proportion":true,"relativeRatio":false,"periodContrastGrowthRate":true,"difference":true,"periodContrastValue":true,"dimensionConvert":false,"magnanimityJson":[]}],"filter":[{"id":"0","values":["2024-04-01 00:00:00","2024-04-10 00:00:00"],"label":"筛选日期","labels":"2024-04-01;2024-04-10","operator":"between","visibletype":"disabled","type":"3","conditiontype":"calendar","name":"筛选日期","uitype":"calendar","title":"介于：2024-04-01 ~ 2024-04-10","acid":"","date_type":4,"is_half":false,"latest_day":7,"contrastType":"yearContrast","contrastValue":"去年","contrastDatetimeV2":{"values":["2023-04-01 08:00:00","2023-04-10 08:00:00"],"acid":"","date_type":4,"is_half":false,"latest_day":7,"defaultTimeFilter":false,"defaultTimeFilterType":0,"userGroupFilterValues":[]},"defaultTimeFilter":true,"defaultTimeFilterType":0,"userGroupFilterValues":[],"enabled":true},{"id":"226","values":["特卖会"],"label":"应用名称","labels":"特卖会;","operator":"in","type":"original","conditiontype":"selection_muti","name":"浏览明细表.app_name","uitype":"selection_muti","title":"属于：特卖会;","acid":"","defaultTimeFilter":false,"defaultTimeFilterType":0,"userGroupFilterValues":[],"enabled":true},{"id":"2856","values":["10037467"],"label":"NOVA专题ID","labels":"10037467","operator":"in","visibletype":"undefined","type":"original","conditiontype":"input","name":"dim_mst_nova_child_page_df.special_id","uitype":"input","title":"属于：10037467","acid":"","defaultTimeFilter":false,"defaultTimeFilterType":0,"userGroupFilterValues":[],"enabled":true,"typede":"dimension"}],"stepList":[{"id":"1763","from":"10","step":"20","groupSize":"5"}],"dimensionJson":{"1375":[{"index":1000,"name":"风格"},{"index":999,"name":"流行元素"}]},"attriMagnanimity":"33"}'

    request: CommonAttributeRequest = CommonAttributeRequest(**json.loads(aa))
    print(request)



可以使用@dataclass 吗，简化一下代码