import logging

from dmsales.api_operations import APIOperations

logger = logging.getLogger(__name__)


class ValidationEndpoints(APIOperations):

    def validation_start(self, name: str, phone: str,
                         postal_code: str, email: str):
        '''
        Returns dictionary with generated task id.

        :param name: name to validate
        :type name: str
        :param phone: phone to validate
        :type phone: str
        :param postal_code: postal code to validate
        :type postal_code: str
        :param email: email to validate
        :type email: str
        :return: Dictionary with task id
        :rtype: dict
        '''                         
        endpoint = '/api/validation/start'

        data = {
            'name': {
                'value': name
            },
            'phone': {
                'value': phone
            },
            'postal_code': {
                'value': postal_code
            },
            'email': {
                'value': email
            }
        }

        data = {k: v for k, v in data.items() if v['value']} # exclude None args
        logger.debug('Calling validation_start method')
        return super().make_post_request(endpoint, json=data)

    def validation_report(self, task_id: str):
        '''
        Returns generated report with validation data for given task id.

        :param task_id: task id generated by calling start endpoint
        :type task_id: str
        :return: report with validation data
        :rtype: dict
        '''        
        endpoint = '/api/validation/report'

        args_dict = {
            'task_id': task_id
        }

        logger.debug('Calling validation_report method')
        return super().make_get_request(endpoint, params=args_dict)