# Path: configuration/models.py
# class MethodologyMaster(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField(default="")
#     order = models.IntegerField(default=0)
#     created_by = models.ForeignKey(User, related_name="methodology_created_by", null=True, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=datetime.now)
#     updated_by = models.ForeignKey(User, related_name="methodology_updated_by", null=True, on_delete=models.CASCADE)
#     updated = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.created = timezone.now()
#         self.updated = timezone.now()
#         return super(MethodologyMaster, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ('name',)
# 
# class ModuleMaster(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField(default="")
#     order = models.IntegerField(default=0)
#     methodology = models.ForeignKey(MethodologyMaster, on_delete=models.CASCADE, null=True, default=None)
#     created_by = models.ForeignKey(User, related_name="module_created_by", null=True, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=datetime.now)
#     updated_by = models.ForeignKey(User, related_name="module_updated_by", null=True, on_delete=models.CASCADE)
#     updated = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.created = timezone.now()
#         self.updated = timezone.now()
#         return super(ModuleMaster, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ('name',)
# 
# class CaseMaster(models.Model):
#     name = models.CharField(max_length=100)
#     module = models.ForeignKey(ModuleMaster, on_delete=models.CASCADE)
#     description = models.TextField(default="")
#     order = models.IntegerField(default=0)
#     created_by = models.ForeignKey(User, related_name="case_module_created_by", null=True, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=datetime.now)
#     updated_by = models.ForeignKey(User, related_name="case_module_updated_by", null=True, on_delete=models.CASCADE)
#     updated = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.created = timezone.now()
#         self.updated = timezone.now()
#         return super(CaseMaster, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ('name',)
# 
# Path: app/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=100)
#     added = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     class Meta:
#         ordering = ('name',)


import json
import os
import django
import sys
from os.path import dirname, abspath
from configuration.models import MethodologyMaster, ModuleMaster, CaseMaster
from app.models import Project
if first_timer:
    answer = "yes"
else:
    print("If you have setup Sh00t in this directory before, this action will reset everything and set up as fresh.")
    print("Are sure you wanna do this?")
    answer = input("[No] | Yes?\n") or ""

if "yes" == answer.lower():
    order = ""
    description_consolidated = ""

    CaseMaster.objects.all().delete()
    ModuleMaster.objects.all().delete()
    MethodologyMaster.objects.all().delete()

    # WAHH
    methodology_master = MethodologyMaster(name="WAHH")
    methodology_master.save()
    wahh_file = open('configuration/data/wahh.json',  'rt', encoding='latin1')
    methodology = json.load(wahh_file)

    for method in methodology['checklist']['Functionality']:
        module_master = ModuleMaster(name=method, methodology=methodology_master, order=methodology['checklist']['Functionality'][method]['order'])
        module_master.save()
        for case in methodology['checklist']['Functionality'][method]['tests']:
            order = '1' + str(methodology['checklist']['Functionality'][method]['order']) + str(methodology['checklist']['Functionality'][method]['tests'][case]['order'])
            descriptions_json = methodology['checklist']['Functionality'][method]['tests'][case]['description']
            description_consolidated = ""
            for description in descriptions_json:
                description_consolidated = description_consolidated + description + '\n\n'

# Path: configuration/models.py
# class MethodologyMaster(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField(default="")
#     order = models.IntegerField(default=0)
#     created_by = models.ForeignKey(User, related_name="methodology_created_by", null=True, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=datetime.now)
#     updated_by = models.ForeignKey(User, related_name="methodology_updated_by", null=True, on_delete=models.CASCADE)
#     updated = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.created = timezone.now()
#         self.updated = timezone.now()
#         return super(MethodologyMaster, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ('name',)
# 
# class ModuleMaster(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField(default="")
#     order = models.IntegerField(default=0)
#     methodology = models.ForeignKey(MethodologyMaster, on_delete=models.CASCADE, null=True, default=None)
#     created_by = models.ForeignKey(User, related_name="module_created_by", null=True, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=datetime.now)
#     updated_by = models.ForeignKey(User, related_name="module_updated_by", null=True, on_delete=models.CASCADE)
#     updated = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.created = timezone.now()
#         self.updated = timezone.now()
#         return super(ModuleMaster, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ('name',)
# 
# class CaseMaster(models.Model):
#     name = models.CharField(max_length=100)
#     module = models.ForeignKey(ModuleMaster, on_delete=models.CASCADE)
#     description = models.TextField(default="")
#     order = models.IntegerField(default=0)
#     created_by = models.ForeignKey(User, related_name="case_module_created_by", null=True, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=datetime.now)
#     updated_by = models.ForeignKey(User, related_name="case_module_updated_by", null=True, on_delete=models.CASCADE)
#     updated = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.created = timezone.now()
#         self.updated = timezone.now()
#         return super(CaseMaster, self).save(*args, **kwargs)
# 
#     class Meta:
#         ordering = ('name',)
# 
# Path: app/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=100)
#     added = models.DateTimeField(default=datetime.now)
# 
#     def __str__(self):  # __unicode__ on Python 2
#         return self.name
# 
#     class Meta:
#         ordering = ('name',)


# Path: reset.py
import json
import os
import django
import sys
from os.path import dirname, abspath
from configuration.models import MethodologyMaster, ModuleMaster, CaseMaster
from app.models import Project

if first_timer:
    answer = "yes"
else:
    print("If you have setup Sh00t in this directory before, this action will reset everything and set up as fresh.")
    print("Are sure you wanna do this?")
    answer = input("[No] | Yes?\n") or ""

if "yes" == answer.lower():
    order = ""
    description_consolidated = ""

    CaseMaster.objects.all().delete()
    ModuleMaster.objects.all().delete()
    MethodologyMaster.objects.all().delete()

    # WAHH
    methodology_master = MethodologyMaster(name="WAHH")
    methodology_master.save()
    wahh_file = open('configuration/data/wahh.json',  'rt', encoding='latin1')
    methodology = json.load(wahh_file)

    for method in methodology['checklist']['Functionality']:
        module_master = ModuleMaster(name=method, methodology=methodology_master, order=methodology['checklist']['Functionality'][method]['order'])
        module_master.save()
        for case in methodology['checklist']['Functionality'][method]['tests']:
            order = '1' + str(methodology['checklist']['Functionality'][method]['order']) + str(methodology['checklist']['Functionality'][method]['tests'][case]['order'])
            descriptions_json = methodology['checklist']['Functionality'][method]['tests'][case]['description']
            description_consolidated = ""
            for description in descriptions_json:
                description_consolidated = description_consolidated + description + '\n\n'

            case = CaseMaster(name=case, description=description_consolidated, module=module_master, order=order)