import json
import uuid

from django.core.urlresolvers import reverse

from models import CrowdModelSpecification


# Required implementation for a new crowd type
class CrowdInterface(object):
    def __init__(self, crowd_name):
        self.crowd_name = crowd_name

    @staticmethod
    def validate_configuration(configuration):
        """ Validate crowd-specific configuration options.

        `configuration` is a dictionary of crowd-specific options as specified
        by the API. This method should verify that all required options are
        included and valid, and return `True` if so and `False` otherwise
        """
        # Dummy implementation, do no validation.
        return True

    @staticmethod
    def create_task(configuration, content):
        """ Do the necessary work to create a task on the crowd platform.

        For example, create a HIT on AMT using the APIs. `configuration` is a
        dictionary containing settings passed via the public API. `content`
        is the actual content for this crowd task. This function must return a
        unique identifier for the new task.
        """
        # Dummy implementation, return a random string
        return uuid.uuid4()

    @staticmethod
    def task_pre_save(task_object):
        """ Process newly created task objects before they are saved to the DB.

        `task_object` will be an UNSAVED object with the `task_model` class
        according to this crowd's model specification. Its task_id field will be
        set to the id returned by the `create_task` method. This method can
        modify the unsaved object (e.g., set custom fields) before it is saved
        to the database. This method SHOULD NOT save the object--it will be
        saved later.
        """
        # Dummy implementation, do nothing
        pass

    @staticmethod
    def group_pre_save(group_object):
        """ Process new task group objects before they are saved to the DB.

        `group_object` will be an UNSAVED object with the `group_model` class
        according to this crowd's model specification. Its group_id field will
        be set to the id passed in via the external API. This method can
        modify the unsaved object (e.g., set custom fields) before it is saved
        to the database. This method SHOULD NOT save the object--it will be
        saved later.
        """
        # Dummy implementation, do nothing
        pass

    @staticmethod
    def delete_tasks(task_objects):
        """ Delete multiple tasks on the crowd platform.

        `task_objects` is a queryset containing multiple instances of the this
        crowd's task_model. This method should not delete the objects
        themselves, just handle the remote cleanup.
        """
        # Dummy implementation, do nothing
        pass

    @staticmethod
    def get_assignment_context(request):