import os
import time

import django
from decouple import config


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'futplus.settings')
django.setup()

from accounts.models import Console, FifaAccount
from sbc.models import SBCWorker
from utils.public_moves import PublicMoves

if __name__ == '__main__':
    def delete_account():
        console_name = config('CONSOLE_NAME', default=None)
        console_object = Console.objects.filter(name=console_name).last()
        if not console_object:
            print('no console name found in .env')
            exit(1)
        fifa_account = FifaAccount.objects.filter(console=console_object).last()
        if not fifa_account:
            print('add one account for this console in system , log in : ', fifa_account)
            exit(1)
        sbc_worker = SBCWorker.objects.filter(
            running_platform='console',
            fifa_account=fifa_account
        ).last()
        if not sbc_worker:
            sbc_worker, created = SBCWorker.objects.get_or_create(
                is_done=True, running_platform='console',
                fifa_account=fifa_account,
            )
        public_moves = PublicMoves(None, sbc_worker, None, None, None)
        public_moves.console_login_utils.focus_on_ps()
        time.sleep(2)
        for iii in range(5):
            current_stat = public_moves.just_find_state()
            if current_stat == 'ps4_main':
                break
            else:
                print('go to home first 4')
                public_moves.ps4_buttons.ps()
                time.sleep(5)
                public_moves.ps4_buttons.cross()
                time.sleep(2)
        result = public_moves.console_accounts_utils.delete_accounts(delete_keys=False)
        print('bot result : ', result)
        while True:
            print('pressing left and right to keep console alive after remove accounts.')
            public_moves.ps4_buttons.right()
            time.sleep(1)
            public_moves.ps4_buttons.left()
            time.sleep(100)


    delete_account()

# todo : for convert this file to .exe enter bellow in terminal
# python -m PyInstaller --onefile --icon=utils\\start_up_methods_1.ico .\startup_methods_3.py
