import requests

from tools.log import logger


class SMS_Client:
    def __init__(self, api_key, country_code):
        self.api_key = api_key
        self.country_code = country_code

    def get_phone_number(self):
        try:
            url = 'https://sms-activate.org/stubs/handler_api.php'
            data = {
                'api_key': self.api_key,
                'action': 'getNumberV2',
                'service': 'fb',
                'forward': 'false',
                'operator': 'any',
                'country': self.country_code,
                'verification': 'false'
            }
            response = requests.get(url, params=data)
            print(response.text)
            if response.status_code == 200:
                return response.json()
            return None
        except Exception as e:
            logger.error(f"Error getting phone number: {e} : {response.text}")
            return None

    def get_verification_code(self, activation_id):
        try:
            url = 'https://sms-activate.org/stubs/handler_api.php'
            data = {
                'api_key': self.api_key,
                'action': 'getStatus',
                'id': activation_id,
            }
            response = requests.get(url, params=data)
            print(response.text)
            if response.status_code == 200:
                if 'OK' in response.text:
                    return response.text.split(':')[1]
            return None
        except Exception as e:
            logger.error(f"Error getting phone number: {e} : {response.text}")
            return None

    def set_status(self, activation_id, status):
        # Implement the logic to set the status of the verification code
        pass
