from features.base_feature import BaseFeature
import dask.dataframe as dd
from exceptions import IrregularExtractArgumentException
from features.get_dtype import get_csv_dtype


class NewFeatures2(BaseFeature):

    def get_loadcols(self):
        cols = [
            "SmartScreen",
            "AVProductStatesIdentifier",
            "OrganizationIdentifier",
            "Census_OSInstallTypeName",
            "Wdft_RegionIdentifier",
            "Census_FirmwareVersionIdentifier",
            "Census_ActivationChannel"
        ]
        return cols

    def extract(self):
        return super().extract()

    def AVPSI53447_SmartScreen(self, df):
        """
        SmartScreen
        AVProductStatesIdentifier
        """
        def reformat(se):
            se = se.str.lower()
            se.replace({
                "promt": "requireadmin",
                "promprt": "requireadmin",
                "prompt" : "requireadmin,",
                "requiredadmin": "requireadmin",
                "block": "requireadmin",
                "warn": "requireadmin",
                "&#x01": "requireadmin",
                "&#x02": "requireadmin",
                "on": "requireadmin",
                "enabled": "requireadmin",
                "off": "exsitsnotset",
                "of": "exsitsnotset",
                "&#x03": "nan",
                "00000000": "nan",
                "deny": "nan",
            }, inplace=True)
            return se

        df = self.load_part().fillna("nan")
        df["SmartScreen"] = reformat(df["SmartScreen"])
        Label = {"requireadmin": 1, "nan": 2, "exsitsnotset": 3}
        df["SmartScreen"] = df["SmartScreen"].map(Label).fillna(2)
        df["SmartScreen"] = df["SmartScreen"].where(df["AVProductStatesIdentifier"] == 53447.0, 0)
        return df[["MachineIdentifier", "SmartScreen"]]

    def Organization_is_null(self, df):
        """
        OrganizationIdentifier
        """
        df["OrganizationIdentifier"] = (df["OrganizationIdentifier"] == df["OrganizationIdentifier"])
        return df[["MachineIdentifier", "OrganizationIdentifier"]]

    def OSInstall(self, df):
        """
        Census_OSInstallTypeName
        """
        Label = {"UUPUpgrade": 0, "IBSClean": 1, "Clean": 1, "Other": 3, "Reset": 1, "Update": 2, "Upgrade": 0, "CleanPCRefresh": 1, "Refresh": 1}
        df["Census_OSInstallTypeName"] = df["Census_OSInstallTypeName"].map(Label).fillna(3)
        return df[["MachineIdentifier", "Census_OSInstallTypeName"]]

    def Wdft_Region_summary(self, df):
        """
        Wdft_RegionIdentifier
        """
        Label = {10.0: 1, 11.0: 2, 3.0: 3, 1.0: 4, 15.0: 5, 7.0: 6}
        df["Wdft_RegionIdentifier"] = df["Wdft_RegionIdentifier"].map(Label).fillna(7)
        return df[["MachineIdentifier", "Wdft_RegionIdentifier"]]

    def FirmwareVersion(self, df):
        """
        Census_FirmwareVersionIdentifier
        """
        Label = {33105.0: 1, 33111.0: 2, 33054.0: 3, 33108.0: 4, 11778.0: 5, 63175.0: 6, 33060.0: 7, 19970.0: 8}
        df["Census_FirmwareVersionIdentifier"] = df["Census_FirmwareVersionIdentifier"].map(Label).fillna(-1)
        return df[["MachineIdentifier", "Census_FirmwareVersionIdentifier"]]

    def ActivationChannel(self, df):
        """
        Census_ActivationChannel
        """
        Label = {"Volume:GVLK": 1, "OEM:NONSLP": 2}
        df["Census_ActivationChannel"] = df["Census_ActivationChannel"].map(Label).fillna(3)
        return df[["MachineIdentifier", "Census_ActivationChannel"]]
