import os
import time
import traceback

import cv2
import pyotp
from django.db import close_old_connections
from django.utils import timezone

from accounts.models import FifaAccountWorkError, FifaAccountDisable, FifaAccountSuspend, FifaAccountBackupCode
from futplus.settings import BASE_DIR, CONSOLE_NAME_LIST, TIME_ZONE
from sbc import ARZBAZI_REPORT_TOPIC_AIRPLANE_THREAD_MESSAGE_ID
from sbc.public_methods import new_print, set_sbc_status, telegram_send_photo, get_image_position, \
    enter_world_xboxs
from accounts.web_login_utils import logout_login
from utils.realy_public_methods import get_db_time

if os.name == 'nt':
    import mouse


class ConsoleErrorUtils:
    def __init__(self, public_moves_instance):
        from utils.public_moves import PublicMoves
        self.public_moves: PublicMoves = public_moves_instance
        self.fifa_account = self.public_moves.fifa_account
        self.sbc_worker = self.public_moves.sbc_worker
        self.ps4_buttons = self.public_moves.ps4_buttons

    def errors(self, excluded_images=None, add_log=True):
        if excluded_images is None:
            excluded_images = []
        error = 0


        img = cv2.imread("screen_shot_tmp.jpg")
        gray_scale_screen = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        crop_errors_box = gray_scale_screen[100:800, 200:1600]
        crop_bottom_buttons = gray_scale_screen[950:1010, 100:1600]
        crop_remote_errors = gray_scale_screen[400:700, 700:1200]
        crop_remote_errors = cv2.resize(crop_remote_errors, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
        cv2.imwrite('cropped_error_tmp.jpg', crop_errors_box)
        cv2.imwrite('cropped_bottom_buttons_tmp.jpg', crop_bottom_buttons)
        cv2.imwrite('cropped_remote_errors_tmp.jpg', crop_remote_errors)
        cropped_error_text = self.public_moves.get_screen_text('cropped_error_tmp.jpg')
        cropped_bottom_buttons_text = self.public_moves.get_screen_text('cropped_bottom_buttons_tmp.jpg')
        cropped_remote_errors_text = self.public_moves.get_screen_text('cropped_remote_errors_tmp.jpg')
        if add_log:
            new_print(self.fifa_account, 'check for errors , cropped_error_text : ', cropped_error_text[:500],
                      ' cropped_bottom_buttons_text : ', cropped_bottom_buttons_text[:500],
                      ' cropped_remote_errors_tmp : ', cropped_remote_errors_text[:500])
        # if self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/advance.png'),
        #                     'screen_shot_tmp.jpg'):
        #     new_print(self.fifa_account, 'error = advance in page')
        #     self.ps4_buttons.cross()
        #     time.sleep(1)
        #     error = 1
        if self.compare_text('connecting to the EA Servers', cropped_error_text):
        # if self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/ea_connecting.png'),
        #                   'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = ea_connecting , waiting time : ', self.public_moves.ea_connecting_wait)
            time.sleep(1)
            self.public_moves.ea_connecting_wait += 1
            if (self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.ea_connecting_wait > 60 * 3):
                new_print(self.fifa_account, 'more than 1200 time ea connecting wait')
                set_sbc_status(self.sbc_worker, 'restarting console', update_time=False)
                self.public_moves.console_login_utils.restart_console()
                self.public_moves.console_open_ultimate()
            error = 1
        # elif self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/exit_ultimate.png'),
        #                     'screen_shot_tmp.jpg'):
        elif self.compare_text('MESSAGE FROM THE FC TEAM', cropped_error_text):
            new_print(self.fifa_account, 'message from the fc team : ', cropped_error_text)
            self.ps4_buttons.cross()
            time.sleep(2)
            error = 1
        elif self.compare_text('Are you sure you want to exit Football Ultimate', cropped_error_text):
            new_print(self.fifa_account, 'error = exit_ultimate')
            self.ps4_buttons.cross()
            time.sleep(1)
            error = 1
        elif (self.compare_text('Connecting to Ultimate team is not possible', cropped_error_text) or
              self.compare_text('You lost your connection to the EA servers', cropped_error_text) or
              self.compare_text('You have lost your online connection', cropped_error_text) or
              self.compare_text('Ea Servers are unavailable right now', cropped_error_text)
        ):
        # elif (self.public_moves.has_image(os.path.join(
        #         BASE_DIR, f'utils/{self.fifa_account.platform}_controls/connection_lost2.png'),
        #         'screen_shot_tmp.jpg') or
        #       self.public_moves.has_image(
        #           os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/connection lost.png'),
        #           'screen_shot_tmp.jpg') or
        #       self.public_moves.has_image(
        #           os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/connection_lost_3.png'),
        #           'screen_shot_tmp.jpg')
        # ):
            # todo : image is for xboxs , add image for other platforms
            new_print(self.fifa_account, 'error = connection lost , 60 second sleep')
            set_sbc_status(self.sbc_worker, 'connection lost', update_time=False)
            time.sleep(60)
            if (self.fifa_account.platform in ['xboxs', 'xbox360'] and
                    self.sbc_worker.status_change_time < timezone.localtime() - timezone.timedelta(minutes=45)):
                set_sbc_status(self.sbc_worker, 'restarting console')
                self.public_moves.console_login_utils.restart_console()
                self.public_moves.console_open_ultimate()
            elif self.fifa_account.platform in ['xboxs', 'xbox360']:
                self.public_moves.close_game()
                time.sleep(5)
                self.public_moves.login_to_account()
                time.sleep(5)
                self.public_moves.go_to_state('ps4_main', 'home_main')
            else:
                # todo : fix this else as if part
                self.ps4_buttons.cross()
                time.sleep(2)
            error = 1
        elif self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/after_buy_in_list.png'),
                'screen_shot_tmp.jpg') and 'after_buy_in_list.png' not in excluded_images:
            new_print(self.fifa_account, 'error = after_buy_in_list')
            if self.public_moves.has_image(
                    os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/swap_with_duplicate.png'),
                    'screen_shot_tmp.jpg'):
                self.ps4_buttons.cross()
                time.sleep(1)
                self.ps4_buttons.cross()
                time.sleep(1)

                self.ps4_buttons.press_and_release_right_joystick(128, 250)
                time.sleep(1)

                self.ps4_buttons.r2()
                time.sleep(2)
                self.ps4_buttons.cross()
                time.sleep(1)
            else:
                new_print(self.fifa_account, 'can not find swap_with_duplicate')
                self.ps4_buttons.circle()
                time.sleep(1.5)
                self.ps4_buttons.up()
                self.ps4_buttons.cross()
                # self.public_moves.go_to_state('transfers', 'play_main')
                # todo : what is kind of bellow codes?
                # uncompleted_worker = self.sbc_worker
                # fifa_account = self.fifa_account
                # logout_login(self.public_moves.sbc_solver_instance, self.sbc_worker, self.fifa_account)
                # sell_items(self.public_moves.sbc_solver_instance, self.sbc_worker, self.fifa_account)
                # time.sleep(1)
                # delete_sold_items(self.se, self.main_dic['header'], self.server_key)
                # time.sleep(1)
                # resp = get_trade_pile(self.fifa_account, self.se, self.main_dic, self.server_key)
                # json_resp = resp.json()
                # trades = json_resp['auctionInfo']
                # must_sell_items = 0
                # for trade in trades:
                #     if trade['tradeState'] != 'active':
                #         must_sell_items = 1
                # if must_sell_items:
                #     self.public_moves.console_open_ultimate()
                #     new_print(self.fifa_account, 'console sell players ...')
                #     self.public_moves.go_to_state('ps4_main', 'transfer_list')
                #     self.search_transfer_list_item(True)
                #     new_print(self.fifa_account, 'console end of sell players ...')

            error = 1
        elif self.compare_text('Type the characters you see', cropped_error_text):
        # elif self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/captcha.png'),
        #                     'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = captcha')
            self.sbc_worker.refresh_from_db()
            last_status = self.sbc_worker.status
            last_status_time = self.sbc_worker.status_change_time
            self.sbc_worker.status = 'captcha'
            self.sbc_worker.status_change_time = timezone.localtime()
            self.sbc_worker.save()
            while True:
                self.public_moves.get_screen_shot()
                if self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/captcha.png'),
                                  'screen_shot_tmp.jpg'):
                    time.sleep(5)
                else:
                    break
            new_print(self.fifa_account, 'captcha solved ...')
            set_sbc_status(self.sbc_worker, last_status)
            time.sleep(10)
            error = 1
        elif self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/scoreboard.png'),
                            'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = first play needed')
            time.sleep(2)
            self.ps4_buttons.option()
            time.sleep(2.5)
            self.ps4_buttons.down()
            time.sleep(1)
            self.ps4_buttons.down()
            time.sleep(1)
            self.ps4_buttons.right()
            self.ps4_buttons.cross()
            time.sleep(2)
            self.ps4_buttons.up()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(5)
            # self.public_moves.wait_for_image(
            #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement.png'))
            # time.sleep(30)
            # self.ps4_buttons.up()
            # time.sleep(1)
            # self.ps4_buttons.cross()
            # time.sleep(1)
            # self.public_moves.get_screen_shot()
            # while not self.public_moves.has_image(
            #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/home_main.png'),
            #         'screen_shot_tmp.jpg'):
            #     self.ps4_buttons.cross()
            #     time.sleep(1)
            #     self.public_moves.get_screen_shot()
            # time.sleep(1)
            # self.ps4_buttons.cross()
            # self.public_moves.wait_for_image(os.path.join(BASE_DIR, 'utils/after_update/update_completed.png'))
            # time.sleep(1)
            # self.ps4_buttons.cross()
            # time.sleep(2)
            error = 1
        elif (self.compare_text('Please read the agreements below', cropped_error_text)
              # self.compare_text('User Agreement', cropped_error_text)
        ):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement_2.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement_3.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'user agrement found')
            time.sleep(30)
            if self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement.png'),
                'screen_shot_tmp.jpg'
            ) or self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement_2.png'),
                'screen_shot_tmp.jpg'
            ) or self.public_moves.has_image(
                    os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement_3.png'),
                    'screen_shot_tmp.jpg'
            ):
                # self.ps4_buttons.up()
                self.ps4_buttons.left()
                time.sleep(1)
                self.ps4_buttons.cross()
                time.sleep(1)
                self.public_moves.get_screen_shot()
                for nm in range(200):
                    if (self.public_moves.has_image(
                            os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/home_main.png'),
                            'screen_shot_tmp.jpg') or
                            self.public_moves.has_image(
                            os.path.join(BASE_DIR, f'utils/xbox_public/redeem_your_gift_card.png'),
                            'screen_shot_tmp.jpg')):
                        break
                    elif self.public_moves.has_image(
                            os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement.png'),
                            'screen_shot_tmp.jpg') or self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement_2.png'),
                'screen_shot_tmp.jpg'
                    ) or self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/user_agreement_3.png'),
                'screen_shot_tmp.jpg'
                    ):
                        self.ps4_buttons.left()
                        time.sleep(1)
                    self.ps4_buttons.cross()
                    time.sleep(1)
                    self.public_moves.get_screen_shot()
                time.sleep(1)
                error = 1
        elif self.compare_text('In order to play Football Ultimate Team', cropped_error_text):
        # elif self.public_moves.has_image(os.path.join(
        #         BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/update_needed.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = In order to play Football Ultimate Team , update needed')
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(10)
            self.public_moves.wait_for_image(os.path.join(
                BASE_DIR, f'utils/{self.fifa_account.platform}_after_update/update_completed.png')
            )
            time.sleep(1)
            self.ps4_buttons.cross()
            # set_sbc_status(self.sbc_worker, 'game update need')
            # new_print(self.fifa_account, 'game update need 2, pressing left and right')
            # for iiie in range(10):
            #     time.sleep(60)
            #     self.ps4_buttons.right()
            #     time.sleep(5)
            #     self.ps4_buttons.left()
            #     time.sleep(5)
            #     self.ps4_buttons.circle()
            error = 1
        elif self.compare_text('DLC Assets Update', cropped_error_text):
        # elif self.public_moves.has_image(os.path.join(
        #         BASE_DIR, f'utils/{self.fifa_account.platform}_controls/dlc_asset_update.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'dlc error')
            self.ps4_buttons.down()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(1)
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/delete_club_lets_get_started.png'),
        #         'screen_shot_tmp.jpg'):
        #     new_print(self.fifa_account, 'error = create club needed')
        #     error = 1
        #     self.public_moves.create_club(need_to_change_state=False)
        #     self.public_moves.go_to_state('ultimate_team', 'play_main')
        #     self.put_on_rest_mode()
        #     self.sbc_worker.refresh_from_db()
        #     self.sbc_worker.has_error = True
        #     self.sbc_worker.error_description = 'create club needed'
        #     self.sbc_worker.must_done = True
        #     self.sbc_worker.save()
        #     self.fifa_account.refresh_from_db()
        #     self.fifa_account.active = False
        #     self.fifa_account.login_status = 0
        #     self.fifa_account.driver = False
        #     self.fifa_account.can_kill_by_mother = False
        #     self.fifa_account.save()
        #     os.system('TASKKILL /F /IM run_console_manager.exe /FI "USERNAME eq %username%"')
        #     os.system('TASKKILL /F /IM run_console_manager.exe /FI "USERNAME eq %username%"')
        #     os.system('TASKKILL /F /IM run_console_manager.exe /FI "USERNAME eq %username%"')
        #     os.system('TASKKILL /F /IM python.exe /FI "USERNAME eq %username%"')

        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/need_to_rename_club.png'),
        #         'screen_shot_tmp.jpg'):
        #     new_print(self.fifa_account, 'error = need to rename club')
        #     error = 1
        #     self.ps4_buttons.cross()
        #     time.sleep(2)
        #     self.ps4_buttons.cross()
        #     time.sleep(2)
        #     self.ps4_buttons.cross()
        #     self.ps4_buttons.cross()
        #     self.ps4_buttons.option()
        #     time.sleep(2)
        #     self.ps4_buttons.down()
        #     self.ps4_buttons.down()
        #     self.ps4_buttons.cross()
        #     time.sleep(2)
        #     self.ps4_buttons.up()
        #     self.ps4_buttons.cross()
        #     time.sleep(5)
        elif self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/starter_pack_select.png'),
                'screen_shot_tmp.jpg') or self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/delete_club_lets_get_started.png'),
                'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = need to select starter pack')
            set_sbc_status(sbc_worker=self.sbc_worker, status='selecting starter pack', update_time=False)
            # self.sbc_worker.refresh_from_db()
            # self.sbc_worker.status = 'selecting starter pack'
            # self.sbc_worker.save()
            self.public_moves.create_club()
            # self.ps4_buttons.circle()
            # time.sleep(1)
            # self.ps4_buttons.up()
            # time.sleep(.5)
            # self.ps4_buttons.cross()
            # time.sleep(1)
            # raise Exception('need to select starter pack')
            error = 1
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/event_page.png'),
        #         'screen_shot_tmp.jpg'
        # ):
        #     new_print(self.fifa_account, 'error = need to select event')
        #     self.sbc_worker.refresh_from_db()
        #     self.sbc_worker.status = 'selecting event'
        #     self.sbc_worker.status_change_time = timezone.localtime()
        #     self.sbc_worker.save()
        #     self.ps4_buttons.cross()
        #     time.sleep(1)
        #     self.ps4_buttons.cross()
        #     time.sleep(10)
        #     self.ps4_buttons.cross()
        #     # todo : images add for xbox 360 and ps . add images for xboxs
        #     for nmt in range(8):
        #         self.public_moves.get_screen_shot()
        #         if self.public_moves.has_image(os.path.join(
        #                 BASE_DIR, f'utils/{self.fifa_account.platform}_controls/transfers_keep_items.png'),
        #                 'screen_shot_tmp.jpg') or self.public_moves.has_image(
        #             os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/after_buy_in_list.png'),
        #             'screen_shot_tmp.jpg'):
        #             time.sleep(1)
        #             self.ps4_buttons.r2()
        #             break
        #         else:
        #             self.ps4_buttons.cross()
        #             time.sleep(5)
        #         if nmt > 6:
        #             raise Exception('need select event')
        #     error = 1

        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/need_to_rename_squad.PNG'),
        #         'screen_shot_tmp.jpg'):
        #     new_print(self.fifa_account, 'error = need to rename squad')
        #     error = 1
        #     self.ps4_buttons.cross()
        elif self.compare_text('please take a few minutes to create a new account or link', cropped_error_text):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/need_link_account_step_1.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'need to link account')
            set_sbc_status(self.sbc_worker, 'link origin account', update_time=False)
            self.public_moves.console_accounts_utils.link_origin_account()
            error = 1
        elif self.compare_text('Are you sure you want to leave Sorting', cropped_error_text):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/sort_item_in_transfer_list.png'),
        #         'screen_shot_tmp.jpg'):
            # todo: images added for ps only.add images for xbox360 and xboxs
            new_print(self.fifa_account, 'error = sort items in transfer list needed . sort it later.')
            for nnn in range(5):
                self.public_moves.get_screen_shot()
                if self.public_moves.has_image(os.path.join(
                        BASE_DIR,
                        f'utils/{self.fifa_account.platform}_controls/sort_item_later_confirm.png'),
                        'screen_shot_tmp.jpg'):
                    break
                else:
                    self.ps4_buttons.up()
                    time.sleep(1)
            self.ps4_buttons.cross()
            error = 1
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/my_squad_menu.png'),
        #         'screen_shot_tmp.jpg'
        # ):
        #     new_print(self.fifa_account, 'need to signin to account')
        #     self.ps4_buttons.circle()
        #     time.sleep(5)
        #     error = 1
        # elif self.public_moves.has_image(os.path.join(
        #         BASE_DIR,
        #         f'utils/{self.fifa_account.platform}_controls/reply_squad.png'),
        #         'screen_shot_tmp.jpg'):
        #     # todo : just xbox360 and ps image added. add other device images too
        #     new_print(self.fifa_account, 'reply squad special game found')
        #     self.ps4_buttons.cross()
        #     time.sleep(3)
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/need_to_sign_in.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/need_to_sign_in_2.png'),
        #     'screen_shot_tmp.jpg'
        # ):
        #     new_print(self.fifa_account, 'need to signin to account')
        #     self.public_moves.close_game()
        #     time.sleep(5)
        #     self.public_moves.login_to_account()
        #     time.sleep(5)
        #     self.public_moves.go_to_state('ps4_main', 'home_main')
        #     error = 1
        elif self.compare_text('You must substitute the injured player before', cropped_error_text):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/injure_middle_game.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'injure middle of game')
            result = self.public_moves.play_football_utils.swap_injury_player()
            error = 1
            if result == 'can not fix':
                set_sbc_status(self.sbc_worker, 'injure middle of game')
                time.sleep(1000)
                raise Exception('injure middle of game')
            else:
                new_print(self.fifa_account, 'injuri fixed')
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/xbox_not_top1.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/xbox_not_top2.png'),
        #     'screen_shot_tmp.jpg'
        # )):
        #     new_print(self.fifa_account, 'xbox is not top app')
        #     raise Exception('xbox app is not top')
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/signin_with_ea_emal.png'),
                'screen_shot_tmp.jpg'
        ):
            new_print(self.fifa_account, 'need to signin to ea account. it`s bug in ea connection')
            self.public_moves.close_game()
            time.sleep(5)
            self.public_moves.login_to_account()
            time.sleep(5)
            self.public_moves.go_to_state('ps4_main', 'home_main')
            error = 1
        elif (self.compare_text('The active profile has been signed out', cropped_error_text) or
              self.compare_text('You must have a Xbox Profile signed in', cropped_error_text)):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/active_profile_signed_out.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/active_profile_signed_out2.png'),
        #     'screen_shot_tmp.jpg'
        # )):
            new_print(self.fifa_account, 'need to signin to account 2')
            self.public_moves.close_game()
            time.sleep(5)
            self.public_moves.login_to_account()
            time.sleep(5)
            self.public_moves.go_to_state('ps4_main', 'home_main')
            error = 1
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/need_sign_in_with_key.png'),
        #         'screen_shot_tmp.jpg'
        # ):
        #     self.public_moves.login_with_key()
        #     time.sleep(5)
        #     self.public_moves.login_to_account()
        #     time.sleep(5)

        elif ('key_duplicate_error.png' not in excluded_images and 'key_duplicate_error2.png' not in excluded_images and
              self.fifa_account.platform in ['xboxs', 'xbox360'] and (
                    self.compare_text('key started playing this on', cropped_error_text) or
                    self.compare_text('key is already playing on', cropped_error_text)
              )):
        #       self.fifa_account.platform in ['xboxs', 'xbox360'] and (
        #         self.public_moves.has_image(
        #             os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/key_duplicate_error.png'),
        #             'screen_shot_tmp.jpg'
        #         ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/key_duplicate_error2.png'),
        #     'screen_shot_tmp.jpg')
        # )):
            new_print(self.fifa_account, 'duplicate key found')
            if self.public_moves.duplicate_key_counter > 3:
                set_sbc_status(self.sbc_worker, 'too many duplicate key found')
                time.sleep(1500)
                raise Exception('too many duplicate key found')
            # self.ps4_buttons.right()
            self.ps4_buttons.left()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(10)
            self.public_moves.duplicate_key_counter += 1
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('needs an update', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(os.path.join(
        #         BASE_DIR,
        #         f'utils/{self.fifa_account.platform}_controls/game_need_update.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'game need update message.')
            self.ps4_buttons.cross()
            time.sleep(10)
            set_sbc_status(self.sbc_worker, 'game update need')
            new_print(self.fifa_account, 'game update need 3, pressing left and right')
            for iiie in range(10):
                time.sleep(60)
                self.ps4_buttons.right()
                time.sleep(5)
                self.ps4_buttons.left()
                time.sleep(5)
                self.ps4_buttons.circle()
            error = 1
        elif self.compare_text('Would you like to switch the active profile to', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/like_switch_accoun.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'need to switch account')
            self.public_moves.close_game()
            time.sleep(5)
            self.public_moves.login_to_account()
            time.sleep(5)
            self.public_moves.go_to_state('ps4_main', 'home_main')
            error = 1
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/unable_load_information.png'),
        #         'screen_shot_tmp.jpg'
        # ):
        #     new_print(self.fifa_account, 'error = unable to load information . try again ...')
        #     self.ps4_buttons.cross()
        #     time.sleep(5)
        #     error = 1
        elif self.compare_text('Your account requires additional authentication on the', cropped_remote_errors_text):
        # elif self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/can_not_find_console4.png'),
        #     'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'need to monitor')
            set_sbc_status(self.sbc_worker, 'need looks good')
            self.public_moves.sbc_solver_instance.send_message(
                None, None, text=f'console : {self.fifa_account.console} need looks good',
                message_thread_id=ARZBAZI_REPORT_TOPIC_AIRPLANE_THREAD_MESSAGE_ID)
            time.sleep(1800)
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (
            self.compare_text('Try again in a while', cropped_remote_errors_text) or
            self.compare_text('Disconnected from cloud gaming', cropped_remote_errors_text)
        ):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/can_not_find_console.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/can_not_find_console2.png'),
        #     'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/can_not_find_console3.png'),
        #     'screen_shot_tmp.jpg'
        # )):
            new_print(self.fifa_account,
                      'error = Can not find Console. may be console not connected to internet or power')
            set_sbc_status(self.sbc_worker, 'try to connect to console', update_time=False)
            if self.public_moves.cant_find_console_counter > 5:
                new_print(self.fifa_account, 'can not connect to console')
                set_sbc_status(self.sbc_worker, 'can not connect to console')
                FifaAccountWorkError.objects.create(fifa_account=self.fifa_account, error_text='airplane')
                self.public_moves.sbc_solver_instance.send_message(
                    None, None, text=f'console : {self.fifa_account.console} airplane',
                    message_thread_id=ARZBAZI_REPORT_TOPIC_AIRPLANE_THREAD_MESSAGE_ID)
                time.sleep(1000)
                raise Exception('can not connect to console')
            else:
                self.public_moves.cant_find_console_counter += 1
            os.system('TASKKILL /F /IM XboxPcApp.exe /FI "USERNAME eq %username%"')
            time.sleep(20)
            self.ps4_buttons.cross()
            time.sleep(2)
            self.ps4_buttons.circle()
            time.sleep(2)
            self.ps4_buttons.circle()
            time.sleep(2)
            open_xbox_app = self.public_moves.xboxs_go_to_app()
            if open_xbox_app and open_xbox_app.get('status_bool') is True:
                new_print(self.fifa_account, 'xbox app opened so need to login to account')
                if len(CONSOLE_NAME_LIST) > 1:
                    self.public_moves.console_login_utils.login_with_start()
                    time.sleep(5)
                self.public_moves.login_to_account()
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (
            self.compare_text('The controller needs to be paired to', cropped_error_text) or
            self.compare_text('You need to have a signed in profile paired', cropped_error_text)
        ):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/controller_need_pair.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/controller_need_pair2.png'),
        #     'screen_shot_tmp.jpg'
        # )):
            new_print(self.fifa_account, 'need to pair controller . quit game')
            self.public_moves.close_game()
            time.sleep(5)
            self.public_moves.login_to_account()
            time.sleep(5)
            self.public_moves.go_to_state('ps4_main', 'home_main')
            error = 1
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/controller_need_signed.png'),
        #         'screen_shot_tmp.jpg'
        # ):
        #     new_print(self.fifa_account, 'need to connect with signed profile')
        #     self.public_moves.close_game()
        #     time.sleep(5)
        #     self.public_moves.login_to_account()
        #     time.sleep(5)
        #     self.public_moves.go_to_state('ps4_main', 'home_main')
        #     error = 1
        elif self.public_moves.has_image(
            os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pre_order_new_game2.png'),
            'screen_shot_tmp.jpg'
        ):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/first_game_warm_up.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pre_order_new_game.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pre_order_new_game2.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'found first game warm up or pre order')
            self.ps4_buttons.circle()
            time.sleep(10)
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/side_menu_opened.png'),
                'screen_shot_tmp.jpg'
        ):
            new_print(self.fifa_account, 'side menu level 1 was opened. i close it.')
            self.ps4_buttons.circle()
            time.sleep(2)
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('Choose the plan thats right for you', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/select_purchase_plan.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'select purchase plan.')
            self.ps4_buttons.circle()
            time.sleep(5)
            error = 1
        elif self.compare_text('Level up your gaming experience', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/level_up_gaming_experince.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'level up gaming experince happend.')
            yes_position = get_image_position(os.path.join(
                BASE_DIR, f'utils/xbox_add_account/yes_im_in.png'),
                'screen_shot_tmp.jpg')
            new_print(self.fifa_account, 'level up gaming experince found yes im in position : ', yes_position)
            if 150 < yes_position.get('top_left')[0] < 400:
                self.ps4_buttons.cross()
            elif 450 < yes_position.get('top_left')[0] < 700:
                self.ps4_buttons.right()
                time.sleep(2)
                self.ps4_buttons.cross()
            elif 750 < yes_position.get('top_left')[0] < 1000:
                self.ps4_buttons.right()
                time.sleep(1)
                self.ps4_buttons.right()
                time.sleep(2)
                self.ps4_buttons.cross()
            else:
                self.ps4_buttons.cross()
            time.sleep(5)
            error = 1
        elif self.compare_text('Replaying this squad will replace your current', cropped_error_text):
        # elif self.public_moves.has_image(os.path.join(
        #         BASE_DIR,
        #         f'utils/{self.fifa_account.platform}_controls/reply_squad.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'reply squad special game message appear. close it.')
            self.public_moves.get_screen_shot()
            if self.public_moves.has_image(os.path.join(
                    BASE_DIR,
                    f'utils/{self.fifa_account.platform}_controls/confirm_reply_squad.png'),
                    'screen_shot_tmp.jpg'):
                self.ps4_buttons.up(sleep_after=.5)
            self.ps4_buttons.cross()
            time.sleep(1)
            self.ps4_buttons.circle()
            time.sleep(1)
        elif self.compare_text('Click or tap here to continue playing', cropped_error_text):
        # elif self.public_moves.has_image(os.path.join(
        #         BASE_DIR,
        #         f'utils/{self.fifa_account.platform}_controls/click_here_continue.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'click on xbox app to continue')
            desktop = os.path.expanduser("~/Desktop")
            print(os.path.join(desktop, 'Xbox.lnk'))
            os.system(os.path.join(desktop, 'Xbox.lnk'))
        else:
            ea_message_found = False
            ea_messages = [
                'successfully claimed your reward',  # clim seasonal rewards
                'IMPORTANT NOTICE',  # notice from fc
                'MESSAGE FROM THE FC TEAM',  # message from the fc
                'Squad Battles Completed',  # squad battle complete first message
                'Here are your rewards for the Squad Battles',  # squad battle rewards as sunday
                'Stay in touch',
                'Your trade could not be completed',
                'Use search filters to narrow your search',  # transfer targets tutorial
                'Items are sent to your Transfer List',  # unassigned tutorial
                'Battle the Community',  # squad battle tutorial
                'Complete Season Objectives',  # season objective
                'Build your squad to complete Moment',  # moments first message
                'Sign-in on this device',  # need to link origin step 0
            ]
            if not ea_message_found:
                for message_text in ea_messages:
                    if self.compare_text(message_text, cropped_error_text):
                        new_print(self.fifa_account, 'error = message text from the fifa team ', message_text)
                        ea_message_found = True
                        self.ps4_buttons.cross()
                        time.sleep(3)
                        error = 1
                        break
            if not ea_message_found:
                for message_item in os.listdir(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_ea_messages/')):
                    if self.public_moves.has_image(os.path.join(
                            BASE_DIR,
                            f'utils/{self.fifa_account.platform}_ea_messages/{message_item}'),
                            'screen_shot_tmp.jpg'):
                        new_print(self.fifa_account, 'error = message image from the fifa team ', message_item)
                        ea_message_found = True
                        self.ps4_buttons.cross()
                        time.sleep(3)
                        error = 1
                        break

        # if self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/connection lost.png'),
        #                   'screen_shot_tmp.jpg'):
        #     new_print(self.fifa_account, 'error = connection lost')
        #     if self.fifa_account.platform in ['xboxs', 'xbox360']:
        #         self.public_moves.close_game()
        #         time.sleep(5)
        #         self.public_moves.login_to_account()
        #         time.sleep(5)
        #         self.public_moves.go_to_state('ps4_main', 'home_main')
        #     else:
        #         # todo : fix this else as if part
        #         self.ps4_buttons.cross()
        #         time.sleep(2)
        #     error = 1
        if self.public_moves.has_image(os.path.join(
                # todo : xbox360 image added. add xboxs and ps image
                BASE_DIR, f'utils/{self.fifa_account.platform}_controls/not_linked.png'),
                'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = not linked')
            set_sbc_status(self.sbc_worker, 'account not linked')
            time.sleep(1000)
            error = 1
        elif self.compare_text('remove some items from your targets list', cropped_error_text):
        # elif self.public_moves.has_image(os.path.join(
        #         # todo : xbox360 image added. add xboxs and ps image
        #         BASE_DIR, f'utils/{self.fifa_account.platform}_controls/transfer_target_full_error.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'error = transfer target full')

            set_sbc_status(self.sbc_worker, 'transfer target full')
            self.ps4_buttons.cross()
            time.sleep(1)
            self.ps4_buttons.circle()
            time.sleep(1)
            self.ps4_buttons.circle()
            time.sleep(1)
            self.public_moves.go_to_state('transfers', 'transfer_targets')
            time.sleep(10)
            self.errors()
            self.ps4_buttons.r2()
            time.sleep(5)
            # self.ps4_buttons.r2()
            # time.sleep(1)
            # self.ps4_buttons.l2()
            # time.sleep(2)
            if self.public_moves.wait_for_images(
                    [os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/after_buy_in_list.png'),
                     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/transfers_keep_items.png')],
                    wait_time=3):
                self.ps4_buttons.circle()
                time.sleep(2)
                self.ps4_buttons.up(sleep_after=.5)
                self.ps4_buttons.cross()
                time.sleep(10)
                self.public_moves.go_to_state('transfers', 'transfer_targets')
                self.ps4_buttons.r2()
                time.sleep(1)
                self.ps4_buttons.r2()
                time.sleep(5)
                self.ps4_buttons.circle()
                set_sbc_status(self.sbc_worker, 'transfer target empty')
            else:
                self.ps4_buttons.r2()
                time.sleep(2)
                self.ps4_buttons.circle()
                time.sleep(1)
            # time.sleep(1000)
            error = 1

        elif (self.fifa_account.platform in ['xboxs', 'xbox360'] and
              'who_are_u.png' not in excluded_images and
              self.public_moves.has_image(
                  os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/who_are_u.png'),
                  'screen_shot_tmp.jpg'
              )):
            new_print(self.fifa_account, 'side menu level 2 was opened. i close it.')
            self.ps4_buttons.circle()
            time.sleep(2)
            self.ps4_buttons.circle()
            time.sleep(2)
            error = 1
        elif (self.compare_text('Player Pick', cropped_error_text) or
              self.compare_text('Are you sure you want to select this player', cropped_error_text)):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pick_loan_player.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pick_loan_player2.png'),
        #     'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pick_loan_player3.png'),
        #     'screen_shot_tmp.jpg'
        # ):
            for iitr in range(5):
                new_print(self.fifa_account, 'error = please select loan. try : ', iitr)
                self.public_moves.get_screen_shot()
                if self.public_moves.has_image(
                        os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/pick_loan_player.png'),
                        'screen_shot_tmp.jpg'
                ) or iitr < 2:
                    new_print(self.fifa_account, 'pressing up and cross')
                    error = 1
                    self.ps4_buttons.up()
                    time.sleep(1)
                    self.ps4_buttons.cross()
                    time.sleep(1)
                time.sleep(2)
        elif self.compare_text('ITEM PICK', cropped_error_text):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/item_pick_icon.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'pick item appear , select players')
            if self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/item_pick_reveal_all.png'),
                'screen_shot_tmp.jpg'
            ):
                new_print(self.fifa_account, 'pick item with reveal all apper')
                self.ps4_buttons.triangle()
                time.sleep(5)
                for ii in range(3):
                    self.ps4_buttons.cross()
                    time.sleep(1)
                    self.ps4_buttons.left()
                    time.sleep(1)
                self.ps4_buttons.square()
                time.sleep(2)
                self.ps4_buttons.up()
                time.sleep(2)
                self.ps4_buttons.cross()
                time.sleep(2)
                new_print(self.fifa_account, 'all select players must be selected')
        elif self.compare_text('are about to sign a loan player to replace', cropped_error_text):
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/select_loan_middle_starter.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'seems select loan middle starter pack , pressing up and cross')
            error = 1
            self.ps4_buttons.up()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(1)
            for iie in range(3):
                self.ps4_buttons.cross()
                time.sleep(5)
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('Do you like the Xbox app', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/do_you_like_xboxapp.png'),
        #         'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'like xbox app')
            not_now_icon = get_image_position(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/do_you_like_xboxapp_later.png'),
                'screen_shot_tmp.jpg'
            )
            mouse.move(not_now_icon['top_left'][0], not_now_icon['top_left'][1])
            mouse.click('left')
            time.sleep(1)
            return 'need reopen xboxapp'
        # elif self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/console_transfer_ban.png'),
        #         'screen_shot_tmp.jpg'):
        #     new_print(self.fifa_account, 'console transfer market is ban ')
        #     self.put_on_rest_mode()
        #     self.fifa_account.refresh_from_db()
        #     self.fifa_account.delete_club_number = 12
        #     self.fifa_account.can_kill_by_mother = False
        #     self.fifa_account.save()
        #     self.sbc_worker.error_description = "account is ban in console"
        #     self.sbc_worker.has_error = True
        #     self.sbc_worker.save()
        #     new_print(self.fifa_account, 'will kill the program')
        #     os.system('TASKKILL /F /IM run_console_manager.exe /FI "USERNAME eq %username%"')
        #     os.system('TASKKILL /F /IM run_console_manager.exe /FI "USERNAME eq %username%"')
        #     os.system('TASKKILL /F /IM run_console_manager.exe /FI "USERNAME eq %username%"')
        #     os.system('TASKKILL /F /IM python.exe /FI "USERNAME eq %username%"')
        #     new_print(self.fifa_account, 'after killing')
        #     raise Exception('console is ban')
        elif 'windows_expire.png' not in excluded_images and self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/windows_expire.png'),
                'screen_shot_tmp.jpg'):
            try:
                telegram_send_photo(self.fifa_account, os.path.join(BASE_DIR, 'screen_shot_tmp.jpg'),
                                    caption=f'windows expire {self.fifa_account} : {self.fifa_account.console}',
                                    message_type='error')
            except:
                new_print(self.fifa_account, 'error on send photo : ')
            new_print(self.fifa_account, '**Windows Expire. FIX IT**')
            set_sbc_status(self.sbc_worker, '**Windows Expire. FIX IT**')
            FifaAccountWorkError.objects.create(fifa_account=self.fifa_account, error_text='**Windows Expire. FIX IT**')
            time.sleep(1000)
            raise Exception('**Windows Expire. FIX IT**')
        elif (self.compare_text('Your account has been disabled', cropped_error_text) or
              self.compare_text('Your account has been blocked from this product due', cropped_error_text)):
        # elif self.public_moves.has_image(
        #         # todo : image xboxs added. xbox360 and ps add
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/account_disable.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, '**Account Disable**')
            FifaAccountWorkError.objects.create(fifa_account=self.fifa_account, error_text='**Account Disable**')
            try:
                telegram_send_photo(self.fifa_account, os.path.join(BASE_DIR, 'screen_shot_tmp.jpg'),
                                    caption=f'Account Disable {self.fifa_account} : {self.fifa_account.console}')
                time.sleep(5)
                telegram_send_photo(self.fifa_account, os.path.join(BASE_DIR, 'user_name_tmp.png'),
                                    caption=f'Account Disable selected user, '
                                            f'name {self.fifa_account.name_in_console} - {self.fifa_account.platform}'
                                            f' {self.fifa_account}')
            except:
                new_print(self.fifa_account, 'error on send telegram photo. traceback : ', traceback.format_exc())
            # todo : this sleep added for check fake disable accounts . remove it after find bug
            for iie in range(10):
                self.ps4_buttons.right()
                self.ps4_buttons.left()
                time.sleep(60)
            # time.sleep(600)
            self.public_moves.close_game()
            close_old_connections()
            logout_login(self.public_moves.sbc_solver_instance, self.sbc_worker, self.fifa_account)
            if FifaAccountDisable.objects.filter(
                fifa_account=self.fifa_account,
                disable_mode=0,
            ).count() > 0:
                new_print(self.fifa_account, 'real account disable')
                set_sbc_status(self.sbc_worker, '**Account Disable**')
                # self.fifa_account.refresh_from_db()
                # self.fifa_account.delete_console_reason = 'account disabled'
                # self.fifa_account.save()
                # last_done_worker = self.fifa_account.sbcworker_set.filter(is_done=True).last()
                # account_disable, created = FifaAccountDisable.objects.get_or_create(
                #     fifa_account=self.fifa_account,
                # )
                # if created:
                #     account_disable.console = self.fifa_account.console
                #     account_disable.last_run_time = last_done_worker.end_time if last_done_worker else None
                #     account_disable.save()
                time.sleep(1000)
                if self.fifa_account.platform in ['xboxs', 'xbox360']:
                    self.public_moves.close_game()
                raise Exception('**Account Disable**')
            else:
                new_print(self.fifa_account, 'fake Account Disable')
                set_sbc_status(self.sbc_worker, 'fake Account Disable')
                time.sleep(300)
                raise Exception('fake Account Disable')
        elif self.compare_text('Device Suspended', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/device_suspend.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, '!**device suspend**!')
            set_sbc_status(self.sbc_worker, '!**device suspend**!')
            time.sleep(3600)
            raise Exception('!**device suspend**!')
        elif self.compare_text('Is your security info up to date', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/your_security_info_update.png'),
        #         'screen_shot_tmp.jpg'):
            for iii in range(3):
                new_print(self.fifa_account, 'xbox ad , your_security_info_update 22 , ', iii)
                self.public_moves.get_screen_shot()
                if self.public_moves.has_image(
                        os.path.join(BASE_DIR, f'utils/xbox_public/your_security_info_update.png'),
                        'screen_shot_tmp.jpg'):
                    self.ps4_buttons.right()
                    time.sleep(1)
                    self.ps4_buttons.up()
                    time.sleep(1)
                    self.ps4_buttons.up()
                    time.sleep(1)
                    self.ps4_buttons.up()
                    time.sleep(1)
                    self.ps4_buttons.up()
                    time.sleep(1)
                    self.ps4_buttons.up()
                    time.sleep(1)
                    self.ps4_buttons.cross()
                    time.sleep(15)
        elif self.compare_text('Limit Reached', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/limit_reached.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, '!**limit reached**!')
            set_sbc_status(self.sbc_worker, '!**limit reached**!')
            for iin in range(100):
                self.ps4_buttons.right()
                self.ps4_buttons.left()
                time.sleep(12)
            close_old_connections()
            # time.sleep(3600)
            # time.sleep(1200)
            raise Exception('!**limit reached**!')

        elif self.compare_text('This account is suspended from the Xbox network', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/xbox_account_suspend.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, '**Account Suspend**')
            if self.public_moves.set_account_suspend:
                set_sbc_status(self.sbc_worker, '**Account Suspend**')
                last_done_worker = self.fifa_account.sbcworker_set.filter(is_done=True).last()
                account_suspend, created = FifaAccountSuspend.objects.get_or_create(
                    fifa_account=self.fifa_account,
                )
                if created:
                    account_suspend.console = self.fifa_account.console
                    account_suspend.last_run_time = last_done_worker.end_time if last_done_worker else None
                    account_suspend.save()
                time.sleep(1000)
            raise Exception('**Account Suspend**')
        elif self.compare_text('Reset Your Password', cropped_error_text):
        # elif self.public_moves.has_image(  # todo : image xboxs added. xbox360 and ps add
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/console_need_reset pass.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'need reset password')
            set_sbc_status(self.sbc_worker, 'need reset password')
            for iee in range(10):
                self.ps4_buttons.right()
                self.ps4_buttons.left()
                time.sleep(100)
            close_old_connections()
            # time.sleep(1000)
            raise Exception('need reset password')
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('temporary network problem', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/temporary_network_problem.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'temporary network problem , restart console')
            set_sbc_status(self.sbc_worker, 'restarting console')
            self.public_moves.console_login_utils.restart_console()
            self.public_moves.console_open_ultimate()
            time.sleep(1)
        elif (self.compare_text('in with the account that bought the game', cropped_error_text) or
              self.compare_text('you own this game or app', cropped_error_text) or
              self.compare_text('To play this, youll need to buy it', cropped_error_text) or
              self.compare_text("this online, make sure you're signed in", cropped_error_text)
        ):
        # elif self.public_moves.has_image(os.path.join(
        #         BASE_DIR,
        #         f'utils/{self.fifa_account.platform}_controls/need_use_key.png'),
        #         'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(os.path.join(
        #     BASE_DIR,
        #     f'utils/{self.fifa_account.platform}_controls/need_use_key_2.png'),
        #     'screen_shot_tmp.jpg'
        # ) or self.public_moves.has_image(os.path.join(
        #     BASE_DIR,
        #     f'utils/{self.fifa_account.platform}_controls/need_use_key_3.png'),
        #     'screen_shot_tmp.jpg'
        # ):
            new_print(self.fifa_account, 'need to open remote play for key user')
            if self.fifa_account.platform == 'ps':
                self.public_moves.login_with_key()
                time.sleep(5)
            elif self.fifa_account.platform in ['xboxs', 'xbox360']:
                self.public_moves.login_with_key()
                new_print(self.fifa_account, 'login with account success step 5')
                time.sleep(5)
                self.public_moves.login_to_account()
                new_print(self.fifa_account, 'login with account success step 6')
                time.sleep(5)
            self.public_moves.go_to_state('ps4_main', 'home_main')
        elif self.compare_text('requires Xbox Game Pass Ultimate', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/cloud_gaming.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'cloud gaming found')
            self.ps4_buttons.right()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(10)
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/r2_player_search.png'),
                'screen_shot_tmp.jpg') or self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/r2_recently_met.png'),
                'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'connect page found, press r2.')
            self.ps4_buttons.reset_to_default()
            time.sleep(1)
            for i in range(10):
                time.sleep(1)
                self.public_moves.get_screen_shot()
                if self.public_moves.has_image(os.path.join(
                        BASE_DIR, f'utils/{self.fifa_account.platform}_controls/r2_player_search.png'),
                        'screen_shot_tmp.jpg') or self.public_moves.has_image(os.path.join(
                    BASE_DIR, f'utils/{self.fifa_account.platform}_controls/r2_recently_met.png'),
                    'screen_shot_tmp.jpg'):
                    new_print(self.fifa_account, 'connect page found, press circle.')
                    self.ps4_buttons.circle()
                    time.sleep(1)
            error = 1
        elif self.compare_text('Make it your home Xbox so you can play games you own', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/after_connection_lost.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'connection lost . will press cross')
            set_sbc_status(self.sbc_worker, 'connection lost', update_time=False)
            time.sleep(60)
            self.ps4_buttons.cross()
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (
                self.public_moves.has_image(os.path.join(BASE_DIR, f'utils/xbox_public/nothing_come_up_yet.png'),
                               'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'searching for game in store, goes here wrongly, press 7 circle')
            for iio in range(7):
                self.ps4_buttons.circle()
                time.sleep(5)
            error = 1
        elif self.compare_text('Are you still there', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/are_you_still_here.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'are you still here?')
            console_one_icon = get_image_position(
                os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/are_you_still_here.png'),
                'screen_shot_tmp.jpg'
            )
            # mouse.move(console_one_icon['bottom_left'][0], console_one_icon['bottom_left'][1])
            # mouse.click('left')
            self.ps4_buttons.cross()
            time.sleep(2)
            self.ps4_buttons.circle()
            time.sleep(1)
        elif self.compare_text('do you want to sync the last saved data we have in the cloud', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/{self.fifa_account.platform}_controls/data_not_synced.png'),
        #         'screen_shot_tmp.jpg'):
            new_print(self.fifa_account, 'data not synced. try to sync')
            self.ps4_buttons.right()
            time.sleep(2)
            self.ps4_buttons.cross()
            time.sleep(20)
        elif (self.compare_text('Something wen wrong', cropped_error_text) or self.compare_text('Fix it at account.live.com', cropped_error_text)):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/account_locked.png'),
        #         'screen_shot_tmp.jpg') or self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/account_locked_2.png'),
        #         'screen_shot_tmp.jpg')):
            try:
                telegram_send_photo(self.fifa_account, os.path.join(BASE_DIR, 'screen_shot_tmp.jpg'),
                                    caption=f'account locked {self.fifa_account} : {self.fifa_account.console}')
            except:
                new_print(self.fifa_account, 'error on send photo : ', traceback.format_exc())
            set_sbc_status(self.sbc_worker, 'account locked')
            new_print(self.fifa_account, 'account locked')
            FifaAccountWorkError.objects.create(fifa_account=self.fifa_account, error_text='account locked')
            for iie in range(10):
                self.ps4_buttons.right()
                self.ps4_buttons.left()
                time.sleep(100)
            # time.sleep(1000)
            close_old_connections()
            raise Exception('account locked')
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('You need this update to use your console, but something went wrong', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/xbox_os_update_need.png'),
        #         'screen_shot_tmp.jpg')):
            set_sbc_status(self.sbc_worker, 'os update need')
            new_print(self.fifa_account, 'os update need')
            self.ps4_buttons.left()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(10)
            self.ps4_buttons.cross()
            for iir in range(10):
                self.ps4_buttons.right()
                self.ps4_buttons.left()
                time.sleep(100)
            # time.sleep(1000)
            close_old_connections()
            raise Exception('os update need')
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/xbox_public/clear_all_filters_game_not_found.png'),
                'screen_shot_tmp.jpg')):
            self.public_moves.can_not_find_game += 1
            new_print(self.fifa_account, 'can not find games , try again , ', self.public_moves.can_not_find_game)
            self.ps4_buttons.ps()
            time.sleep(5)
            self.ps4_buttons.cross()
            time.sleep(5)
            error = 1
            set_sbc_status(self.sbc_worker, 'can not find game')
            # if self.public_moves.can_not_find_game > 2:
            #     self.public_moves.can_not_find_game = 0
            #     set_sbc_status(self.sbc_worker, 'restarting console')
            #     self.public_moves.console_login_utils.restart_console()
            #     self.public_moves.console_open_ultimate()
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (
            self.compare_text('There was a problem signing in, but it should work if you try again', cropped_error_text) or
            self.compare_text('Too many people are signed in', cropped_error_text)
        ):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/xbox_public/too_many_sign_in.png'),
        #     'screen_shot_tmp.jpg') or self.public_moves.has_image(
        #     os.path.join(BASE_DIR, f'utils/xbox_public/too_many_sign_in_2.png'),
        #     'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'too many sign in account in console , restart console')
            set_sbc_status(self.sbc_worker, 'restarting console')
            self.public_moves.console_login_utils.restart_console()
            self.public_moves.console_open_ultimate()
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('Redeem your gift card', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/redeem_your_gift_card.png'),
        #         'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'redeem your gift card , how goes here ? its bug')
            for iiee in range(10):
                self.ps4_buttons.circle()
                time.sleep(10)
            found_state = self.public_moves.just_find_state()
            for iie in range(3):
                found_state = self.public_moves.just_find_state()
                if found_state:
                    new_print(self.fifa_account, 'after press 5 circle state found ', found_state)
                    break
                self.errors()
            if not found_state:
                new_print(self.fifa_account, 'after press 5 circle state not found ', found_state)
                self.ps4_buttons.ps()
                time.sleep(1)
                self.ps4_buttons.cross()
                time.sleep(1)
                self.public_moves.close_game(raise_error=False)
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('Discover your next favorite game', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/discover_your_favorite_game.png'),
        #         'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'xbox ad , discover favorite game')
            self.ps4_buttons.circle()
            time.sleep(2)
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/xbox_public/take_the_survey.png'),
                'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'xbox remote play ads . press circle')
            self.ps4_buttons.circle()
            time.sleep(1)
            error = 1
        elif self.compare_text('Which one do you want to use', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/which_want_use.png'),
        #         'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'which_want_use appear')
            self.ps4_buttons.up()
            time.sleep(1)
            self.ps4_buttons.cross()
            time.sleep(5)
            error = 1
        elif self.fifa_account.platform in ['xboxs', 'xbox360'] and self.compare_text('Login Verification', cropped_error_text):
        # elif self.fifa_account.platform in ['xboxs', 'xbox360'] and (self.public_moves.has_image(
        #         os.path.join(BASE_DIR, f'utils/xbox_public/login_verification.png'),
        #         'screen_shot_tmp.jpg')):
            new_print(self.fifa_account, 'need login verification')
            set_sbc_status(self.sbc_worker, 'login verification', update_time=False)
            if not self.public_moves.has_image(
                os.path.join(BASE_DIR, f'utils/xbox_public/login_verification_receive_menu.png'),
                'screen_shot_tmp.jpg'):
                self.ps4_buttons.cross(sleep_after=1)
            self.ps4_buttons.down()
            time.sleep(1)
            self.ps4_buttons.cross(sleep_after=1)
            self.ps4_buttons.down()
            time.sleep(1)
            self.ps4_buttons.cross(sleep_after=5)
            self.ps4_buttons.cross(sleep_after=5)
            backup_code = FifaAccountBackupCode.objects.filter(fifa_account__id=self.fifa_account.id).first()
            if backup_code and backup_code.app_code:
                try:
                    db_time = int(get_db_time(timezone_=TIME_ZONE).timestamp())
                    totp_code = pyotp.TOTP(backup_code.app_code).at(db_time)
                    # totp_code = pyotp.TOTP(backup_code.app_code).now()
                except Exception as error:
                    new_print(self.fifa_account, 'error on totp : ', error)
                    set_sbc_status(self.sbc_worker, 'bad app code', update_time=False)
                    time.sleep(1000)
                    totp_code = 111111
                enter_world_xboxs(self, str(totp_code))
                time.sleep(1)
                self.ps4_buttons.option()
                time.sleep(1)
                self.ps4_buttons.down()
                time.sleep(1)
                self.ps4_buttons.cross()
                time.sleep(30)
                new_print(self.fifa_account, 'login verification code success')
            else:
                set_sbc_status(self.sbc_worker, 'no app code', update_time=False)
                time.sleep(1000)

        return error

    def compare_text(self, small_text: str, large_text: str):
        if (small_text.lower().replace(',', '').replace('  ', ' ') in
                large_text.lower().replace(',', '').replace("'", '').replace('\n', '').replace('\t', '').replace('  ', ' ')):
            return True
        return False
