from clointfusion.check_system import os_name, windows_os, mac_os, linux_os, python_version, python_37, python_38, python_39, python_310, report_error

# Functions Represent in this file


if os_name == windows_os:

    # Windows OS - Python 3.7
    if python_version == python_37:

        def find(function_partial_name=""):
            # Description:
            """
            Description of the function
            """

            # import section
            import pyinspect as pi
            # Response section
            status = False
            data = None

            try:
                if function_partial_name:
                    import clointfusion.clointfusion as cf_docs
                    pi.search(cf_docs, name=function_partial_name)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def pause_program(seconds="5"):

            # Description:
            """
            Stops the program for given seconds
            """

            # import section
            import time

            # Response section
            status = False
            data = None

            try:
                seconds = int(seconds)
                time.sleep(seconds)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def download_this_file(url="", output_folder_path=""):
            # Description:
            """
            Downloads a given url file to BOT output folder or Browser's Download folder
            """

            # import section
            import webbrowser
            import requests
            from pathlib import Path
            from clointfusion.clointfusion import message_toast
            import os
            # Response section
            status = False
            data = None
            if not output_folder_path:
                clointfusion_directory = r"C:\Users\{}\ClointFusion".format(
                    str(os.getlogin()))
                output_folder_path = Path(os.path.join(
                    clointfusion_directory, "Output"))

            try:
                if not url:
                    raise Exception("URL is required")

                if "export" in url:
                    webbrowser.open_new(url)

                else:
                    extension = str(url).rsplit(".", 1)[1]
                    r = requests.get(url)
                    download_file_path = output_folder_path / \
                        "downloaded_cf.{}".format(extension)

                    with open(download_file_path, 'wb') as f:
                        f.write(r.content)

                    message_toast("File downloaded",
                                  file_folder_path=download_file_path)
                    data = download_file_path

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def clear_screen():
            # Description:
            """
            Clears Python Interpreter Terminal Window Screen

            """

            # import section
            import os
            # Response section
            status = False
            data = None

            try:
                command = 'clear'
                if os.name in ('nt', 'dos'):  # If Machine is running on Windows, use cls
                    command = 'cls'
                os.system(command)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def show_emoji(strInput="", print_emoji=False):
            """
            Function which prints Emojis

            Usage: 
            print(show_emoji('thumbsup'))
            print("OK",show_emoji('thumbsup'))
            Default: thumbsup
            """
            import emoji

            # Response section
            status = False
            data = None

            try:
                if not strInput:
                    data = emoji.emojize(":{}:".format(
                        str('thumbsup').lower()), use_aliases=True, var="emoji_type")
                    if print_emoji:
                        print(data)
                else:
                    data = emoji.emojize(":{}:".format(
                        str(strInput).lower()), use_aliases=True, variant="emoji_type")
                    if print_emoji:
                        print(data)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]

        def print_with_magic_color(strMsg: str = "", magic: bool = False):
            """
            Function used for printing strings in color
            Args : Message (str): string which needs to be printed in color
                magic : (bool) :If each letter/character in the string is to be printed with different color
            Returns : None

            """
            import random
            from colored import fg, attr
            # Response section
            status = False
            data = None

            try:
                if magic == False:
                    fg_random = random.randint(2, 255)

                    while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                        fg_random = random.randint(2, 255)

                    print('%s %s  %s' % (fg(fg_random), strMsg, attr(1)))
                else:
                    for ch in strMsg:
                        try:
                            fg_random = random.randint(2, 255)
                            while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                                fg_random = random.randint(2, 255)
                            print('%s%s%s' %
                                  (fg(fg_random), ch, attr(1)), sep='', end='')
                        except:
                            print('%s' % (fg(1), attr('reset')),
                                  ch, sep='', end='')

                reset = attr('reset')
                print(reset)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]


# Windows OS - Python 3.8
    elif python_version == python_38:

        def find(function_partial_name=""):
            # Description:
            """
            Description of the function
            """

            # import section
            import pyinspect as pi
            # Response section
            status = False
            data = None

            try:
                if function_partial_name:
                    import clointfusion.clointfusion as cf_docs
                    pi.search(cf_docs, name=function_partial_name)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def pause_program(seconds="5"):

            # Description:
            """
            Stops the program for given seconds
            """

            # import section
            import time

            # Response section
            status = False
            data = None

            try:
                seconds = int(seconds)
                time.sleep(seconds)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def download_this_file(url="", output_folder_path=""):
            # Description:
            """
            Downloads a given url file to BOT output folder or Browser's Download folder
            """

            # import section
            import webbrowser
            import requests
            from pathlib import Path
            from clointfusion.clointfusion import message_toast
            import os
            # Response section
            status = False
            data = None
            if not output_folder_path:
                clointfusion_directory = r"C:\Users\{}\ClointFusion".format(
                    str(os.getlogin()))
                output_folder_path = Path(os.path.join(
                    clointfusion_directory, "Output"))

            try:
                if not url:
                    raise Exception("URL is required")

                if "export" in url:
                    webbrowser.open_new(url)

                else:
                    extension = str(url).rsplit(".", 1)[1]
                    r = requests.get(url)
                    download_file_path = output_folder_path / \
                        "downloaded_cf.{}".format(extension)

                    with open(download_file_path, 'wb') as f:
                        f.write(r.content)

                    message_toast("File downloaded",
                                  file_folder_path=download_file_path)
                    data = download_file_path

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def clear_screen():
            # Description:
            """
            Clears Python Interpreter Terminal Window Screen

            """

            # import section
            import os
            # Response section
            status = False
            data = None

            try:
                command = 'clear'
                if os.name in ('nt', 'dos'):  # If Machine is running on Windows, use cls
                    command = 'cls'
                os.system(command)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def show_emoji(strInput="", print_emoji=False):
            """
            Function which prints Emojis

            Usage: 
            print(show_emoji('thumbsup'))
            print("OK",show_emoji('thumbsup'))
            Default: thumbsup
            """
            import emoji

            # Response section
            status = False
            data = None

            try:
                if not strInput:
                    data = emoji.emojize(":{}:".format(
                        str('thumbsup').lower()), use_aliases=True, var="emoji_type")
                    if print_emoji:
                        print(data)
                else:
                    data = emoji.emojize(":{}:".format(
                        str(strInput).lower()), use_aliases=True, variant="emoji_type")
                    if print_emoji:
                        print(data)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]

        def print_with_magic_color(strMsg: str = "", magic: bool = False):
            """
            Function used for printing strings in color
            Args : Message (str): string which needs to be printed in color
                magic : (bool) :If each letter/character in the string is to be printed with different color
            Returns : None

            """
            import random
            from colored import fg, attr
            # Response section
            status = False
            data = None

            try:
                if magic == False:
                    fg_random = random.randint(2, 255)

                    while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                        fg_random = random.randint(2, 255)

                    print('%s %s  %s' % (fg(fg_random), strMsg, attr(1)))
                else:
                    for ch in strMsg:
                        try:
                            fg_random = random.randint(2, 255)
                            while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                                fg_random = random.randint(2, 255)
                            print('%s%s%s' %
                                  (fg(fg_random), ch, attr(1)), sep='', end='')
                        except:
                            print('%s' % (fg(1), attr('reset')),
                                  ch, sep='', end='')

                reset = attr('reset')
                print(reset)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]


# Windows OS - Python 3.9
    elif python_version == python_39:

        def find(function_partial_name=""):
            # Description:
            """
            Description of the function
            """

            # import section
            import pyinspect as pi
            # Response section
            status = False
            data = None

            try:
                if function_partial_name:
                    import clointfusion.clointfusion as cf_docs
                    pi.search(cf_docs, name=function_partial_name)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def pause_program(seconds="5"):

            # Description:
            """
            Stops the program for given seconds
            """

            # import section
            import time

            # Response section
            status = False
            data = None

            try:
                seconds = int(seconds)
                time.sleep(seconds)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def download_this_file(url="", output_folder_path=""):
            # Description:
            """
            Downloads a given url file to BOT output folder or Browser's Download folder
            """

            # import section
            import webbrowser
            import requests
            from pathlib import Path
            from clointfusion.clointfusion import message_toast
            import os
            # Response section
            status = False
            data = None
            if not output_folder_path:
                clointfusion_directory = r"C:\Users\{}\ClointFusion".format(
                    str(os.getlogin()))
                output_folder_path = Path(os.path.join(
                    clointfusion_directory, "Output"))

            try:
                if not url:
                    raise Exception("URL is required")

                if "export" in url:
                    webbrowser.open_new(url)

                else:
                    extension = str(url).rsplit(".", 1)[1]
                    r = requests.get(url)
                    download_file_path = output_folder_path / \
                        "downloaded_cf.{}".format(extension)

                    with open(download_file_path, 'wb') as f:
                        f.write(r.content)

                    message_toast("File downloaded",
                                  file_folder_path=download_file_path)
                    data = download_file_path

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def clear_screen():
            # Description:
            """
            Clears Python Interpreter Terminal Window Screen

            """

            # import section
            import os
            # Response section
            status = False
            data = None

            try:
                command = 'clear'
                if os.name in ('nt', 'dos'):  # If Machine is running on Windows, use cls
                    command = 'cls'
                os.system(command)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def show_emoji(strInput="", print_emoji=False):
            """
            Function which prints Emojis

            Usage: 
            print(show_emoji('thumbsup'))
            print("OK",show_emoji('thumbsup'))
            Default: thumbsup
            """
            import emoji

            # Response section
            status = False
            data = None

            try:
                if not strInput:
                    data = emoji.emojize(":{}:".format(
                        str('thumbsup').lower()), use_aliases=True, var="emoji_type")
                    if print_emoji:
                        print(data)
                else:
                    data = emoji.emojize(":{}:".format(
                        str(strInput).lower()), use_aliases=True, variant="emoji_type")
                    if print_emoji:
                        print(data)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]

        def print_with_magic_color(strMsg: str = "", magic: bool = False):
            """
            Function used for printing strings in color
            Args : Message (str): string which needs to be printed in color
                magic : (bool) :If each letter/character in the string is to be printed with different color
            Returns : None

            """
            import random
            from colored import fg, attr
            # Response section
            status = False
            data = None

            try:
                if magic == False:
                    fg_random = random.randint(2, 255)

                    while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                        fg_random = random.randint(2, 255)

                    print('%s %s  %s' % (fg(fg_random), strMsg, attr(1)))
                else:
                    for ch in strMsg:
                        try:
                            fg_random = random.randint(2, 255)
                            while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                                fg_random = random.randint(2, 255)
                            print('%s%s%s' %
                                  (fg(fg_random), ch, attr(1)), sep='', end='')
                        except:
                            print('%s' % (fg(1), attr('reset')),
                                  ch, sep='', end='')

                reset = attr('reset')
                print(reset)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]


# Windows OS - Python 3.10
    elif python_version == python_310:

        def find(function_partial_name=""):
            # Description:
            """
            Description of the function
            """

            # import section
            import pyinspect as pi
            # Response section
            status = False
            data = None

            try:
                if function_partial_name:
                    import clointfusion.clointfusion as cf_docs
                    pi.search(cf_docs, name=function_partial_name)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def pause_program(seconds="5"):

            # Description:
            """
            Stops the program for given seconds
            """

            # import section
            import time

            # Response section
            status = False
            data = None

            try:
                seconds = int(seconds)
                time.sleep(seconds)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def download_this_file(url="", output_folder_path=""):
            # Description:
            """
            Downloads a given url file to BOT output folder or Browser's Download folder
            """

            # import section
            import webbrowser
            import requests
            from pathlib import Path
            from clointfusion.clointfusion import message_toast
            import os
            # Response section
            status = False
            data = None
            if not output_folder_path:
                clointfusion_directory = r"C:\Users\{}\ClointFusion".format(
                    str(os.getlogin()))
                output_folder_path = Path(os.path.join(
                    clointfusion_directory, "Output"))

            try:
                if not url:
                    raise Exception("URL is required")

                if "export" in url:
                    webbrowser.open_new(url)

                else:
                    extension = str(url).rsplit(".", 1)[1]
                    r = requests.get(url)
                    download_file_path = output_folder_path / \
                        "downloaded_cf.{}".format(extension)

                    with open(download_file_path, 'wb') as f:
                        f.write(r.content)

                    message_toast("File downloaded",
                                  file_folder_path=download_file_path)
                    data = download_file_path

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def clear_screen():
            # Description:
            """
            Clears Python Interpreter Terminal Window Screen

            """

            # import section
            import os
            # Response section
            status = False
            data = None

            try:
                command = 'clear'
                if os.name in ('nt', 'dos'):  # If Machine is running on Windows, use cls
                    command = 'cls'
                os.system(command)

                # If the function returns a value, it should be assigned to the data variable.
                # data = value
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status == True and data != None:
                    return [status, data]
                return [status]

        def show_emoji(strInput="", print_emoji=False):
            """
            Function which prints Emojis

            Usage: 
            print(show_emoji('thumbsup'))
            print("OK",show_emoji('thumbsup'))
            Default: thumbsup
            """
            import emoji

            # Response section
            status = False
            data = None

            try:
                if not strInput:
                    data = emoji.emojize(":{}:".format(
                        str('thumbsup').lower()), use_aliases=True, var="emoji_type")
                    if print_emoji:
                        print(data)
                else:
                    data = emoji.emojize(":{}:".format(
                        str(strInput).lower()), use_aliases=True, variant="emoji_type")
                    if print_emoji:
                        print(data)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]

        def print_with_magic_color(strMsg: str = "", magic: bool = False):
            """
            Function used for printing strings in color
            Args : Message (str): string which needs to be printed in color
                magic : (bool) :If each letter/character in the string is to be printed with different color
            Returns : None

            """
            import random
            from colored import fg, attr
            # Response section
            status = False
            data = None

            try:
                if magic == False:
                    fg_random = random.randint(2, 255)

                    while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                        fg_random = random.randint(2, 255)

                    print('%s %s  %s' % (fg(fg_random), strMsg, attr(1)))
                else:
                    for ch in strMsg:
                        try:
                            fg_random = random.randint(2, 255)
                            while fg_random in [8, *range(15, 28), 22, 23, *range(51, 68), 77, *range(87, 99), 114, 149, *range(231, 250)]:
                                fg_random = random.randint(2, 255)
                            print('%s%s%s' %
                                  (fg(fg_random), ch, attr(1)), sep='', end='')
                        except:
                            print('%s' % (fg(1), attr('reset')),
                                  ch, sep='', end='')

                reset = attr('reset')
                print(reset)
            except Exception as e:
                report_error(e)

            else:
                status = True
            finally:
                if status is True and data is not None:
                    return [status, data]
                return [status]


    else:
        raise Exception("Python version not supported")


elif os_name == linux_os:

    # Ubuntu OS - Python 3.7
    if python_version == python_37:
        pass


# Ubuntu OS - Python 3.8
    elif python_version == python_38:
        pass


# Ubuntu OS - Python 3.9
    elif python_version == python_39:
        pass


# Ubuntu OS - Python 3.10
    elif python_version == python_310:
        pass

    else:
        raise Exception("Python version not supported")


elif os_name == mac_os:

    # Ubuntu OS - Python 3.7
    if python_version == python_37:
        pass


# Ubuntu OS - Python 3.8
    elif python_version == python_38:
        pass


# Ubuntu OS - Python 3.9
    elif python_version == python_39:
        pass


# Ubuntu OS - Python 3.10
    elif python_version == python_310:
        pass

    else:
        raise Exception("Python version not supported")
