from __future__ import unicode_literals

from django.db import models
from django.utils import timezone

class Target(models.Model):
    """
    A particular static target endpoint that the attack can apply to
    e.g. gmail csrf, facebook message
    """
    endpoint = models.CharField(max_length=255)
    prefix = models.CharField(max_length=255)
    alphabet = models.CharField(max_length=255)

    maxreflectionlength = models.IntegerField(
        default=0,
        help_text=('The maximum length that will be reflected by the service '
                   'the designated location within the endpoint. If this is 0 '
                   'then there is no limit in the reflection length.')
    )

class Victim(models.Model):
    """
    A particular instance of a target for a particular user-victim
    e.g. dionyziz@gmail.com
    """
    target = models.ForeignKey(Target)
    # TODO: method (divide & conquer, etc.)

class SampleSet(models.Model):
    """
    A set of samples collected for a particular victim pertaining to an alphabet
    vector used to extend a known secret.
    """
    victim = models.ForeignKey(Victim)
    # number of samples contained in the set
    amount = models.IntegerField(
        default=1,
        help_text="Number of samples contained in the sampleset"
    )

    # sampleset knownstate: knownsecret and knownalphabet
    knownsecret = models.CharField(
        default="",
        max_length=255,
        help_text="Known secret before the sample set was collected"
    )
    # assert(self.knownsecret[0:len(self.victim.target.prefix)] == self.victim.target.prefix)
    knownalphabet = models.CharField(
        max_length=255,
        help_text="The candidate alphabet for the next unknown character"
    )
    # assert(all([c in self.victim.target.alphabet for c in self.knownalphabet]))

    # candidate state
    candidatealphabet = models.CharField(
        max_length=255,
        help_text=("The alphabet vector that is attempted in this particular "
                   "sample set."
                   "When performing a divide and conquer attack, this will "
                   "typically be a subset of the knownnextalphabet. In an "
                   "iterative attack, it will be a single symbol of "
                   "knownnextalphabet.")
    )
    # assert(all([c in self.knownalphabet for c in self.candidatealphabet]))

    data = models.TextField(
        default="",
        help_text="The raw data collected on the network for this sampleset"
    )

    started = models.DateTimeField(
        default=timezone.now,
        help_text="Date and time at which sample set collection was started"
    )
    completed = models.DateTimeField(
        null=True,
        blank=True,
        help_text=("When we stopped collecting samples for this sampleset, "
                   "successfully or not")
    )
    success = models.BooleanField(
        default=False,
        help_text=("Whether the samples in this sampleset were all collected "
                  "successfully")
    )

class AttackVectorElement(models.Model):
    sampleset = models.ForeignKey(SampleSet)
    symbol = models.CharField(max_length=1)

@@ -245,24 +245,25 @@
 age%0A    %22%22%22%0A
+%0A
     endpoint
@@ -274,32 +274,41 @@
 odels.CharField(
+%0A        
 max_length=255)%0A
@@ -309,102 +309,274 @@
 =255
-)
+,
 %0A    
-prefix = models.CharField(max_length=255)%0A    alphabet = models.CharField(max_length=255
+    help_text=(%22The endpoint in full URL form, including 'https://'.%22%0A                   %22The endpoint string must contain a '%25s' to mark the %22%0A                   %22position in which the string-to-be-reflected will be %22%0A                   %22replaced into.%22)%0A    
 )%0A%0A 
@@ -873,24 +873,381 @@
 h.')%0A    )%0A%0A
+    prefix = models.CharField(%0A        max_length=255,%0A        help_text=(%22The known prefix of the secret used to bootstrap the %22%0A                   %22attack.%22)%0A    )%0A%0A    alphabet = models.CharField(%0A        max_length=255,%0A        help_text=(%22This set contains all the candidate symbols each %22,%0A                   %22character of the secret can be.%22)%0A    )%0A%0A
 class Victim

Add help texts documenting target model fields