# Path: diag_app/models.py
# class Vote(models.Model):
#     tech = models.ForeignKey(Tech)
#     solution = models.ForeignKey(Solution, related_name='votes')
#     value = models.IntegerField(default=1)
# 
# class Problem(models.Model):
#     title = models.CharField(max_length=65)
#     system = models.ForeignKey(System, related_name='problems')
#     description = models.TextField(max_length=500)
#     tech = models.ForeignKey(Tech, related_name='problems')
#     model = models.ForeignKey(Model)
#     posted = models.DateTimeField(auto_now=True)
# 
# class Solution(models.Model):
#     description = models.TextField(max_length=500)
#     time_required = models.FloatField(default=0)
#     parts_cost = models.DecimalField(max_digits=6, decimal_places=2)
#     problem = models.ForeignKey(Problem, related_name='solutions')
#     tech = models.ForeignKey(Tech, related_name='solutions')
#     posted = models.DateTimeField(auto_now=True)
#     score = models.IntegerField(default=0)
# 
# class Tech(models.Model):
#     experience = models.IntegerField(default=0)
#     job_title = models.CharField(max_length=25)
#     shop = models.CharField(max_length=25)
#     user = models.OneToOneField(User)
#     tech_rating = models.IntegerField(default=0)
# 
# class Rating(models.Model):
#     tech = models.ForeignKey(Tech)
#     value = models.IntegerField(default=5)
# 
# class System(models.Model):
#     name = models.CharField(max_length=25)
# 
# class Brand(models.Model):
#     name = models.CharField(max_length=25)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# Path: diag_app/models.py
# class Model(models.Model):
#     name = models.CharField(max_length=40)
#     brand = models.ForeignKey(Brand)
#     year = models.IntegerField(default=0)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# class Problem_Model(models.Model):
#     problem = models.ForeignKey(Problem)
#     model = models.ForeignKey(Model)
# 
# class Commit(models.Model):
#     solution = models.ForeignKey(Solution, related_name='commits')
#     tech = models.ForeignKey(Tech)
#     posted = models.DateTimeField(auto_now=True)
#     text = models.TextField(max_length=200)
# 
# class Notification(models.Model):
#     tech = models.ForeignKey(Tech, related_name='techs')
#     message = models.CharField(max_length=20)
#     # is this the best way to link notifications to events?
#     solution = models.ForeignKey(Solution, related_name='solution',null=True)
#     commit = models.ForeignKey(Commit, related_name='commit',null=True)
#     posted = models.DateTimeField(auto_now=True)


from .models import Vote, Problem, Solution, Tech, Rating, System, Brand
from .models import Model, Problem_Model, Commit, Notification
from django.contrib.auth.models import User
from rest_framework import serializers
from django.contrib.auth import login

class CommitSerializer(serializers.ModelSerializer):

    class Meta:
        model = Commit
        fields = ['id', 'solution', 'tech', 'posted', 'text', 'url']


class VoteSerializer(serializers.ModelSerializer):

    class Meta:
        model = Vote
        fields = "__all__"


class SolutionGetSerializer(serializers.ModelSerializer):
    votes = VoteSerializer(many=True, read_only=True)
    commits = CommitSerializer(many=True, read_only=True)
    tech = TechGetSerializer(many=False, read_only=True)

    class Meta:
        model = Solution
        fields = ['id', 'description', 'time_required', 'parts_cost',
                  'problem', 'tech', 'posted', 'score', 'commits',
                  'votes', 'url']


class SolutionPostSerializer(serializers.ModelSerializer):

    class Meta:

# Path: diag_app/models.py
# class Vote(models.Model):
#     tech = models.ForeignKey(Tech)
#     solution = models.ForeignKey(Solution, related_name='votes')
#     value = models.IntegerField(default=1)
# 
# class Problem(models.Model):
#     title = models.CharField(max_length=65)
#     system = models.ForeignKey(System, related_name='problems')
#     description = models.TextField(max_length=500)
#     tech = models.ForeignKey(Tech, related_name='problems')
#     model = models.ForeignKey(Model)
#     posted = models.DateTimeField(auto_now=True)
# 
# class Solution(models.Model):
#     description = models.TextField(max_length=500)
#     time_required = models.FloatField(default=0)
#     parts_cost = models.DecimalField(max_digits=6, decimal_places=2)
#     problem = models.ForeignKey(Problem, related_name='solutions')
#     tech = models.ForeignKey(Tech, related_name='solutions')
#     posted = models.DateTimeField(auto_now=True)
#     score = models.IntegerField(default=0)
# 
# class Tech(models.Model):
#     experience = models.IntegerField(default=0)
#     job_title = models.CharField(max_length=25)
#     shop = models.CharField(max_length=25)
#     user = models.OneToOneField(User)
#     tech_rating = models.IntegerField(default=0)
# 
# class Rating(models.Model):
#     tech = models.ForeignKey(Tech)
#     value = models.IntegerField(default=5)
# 
# class System(models.Model):
#     name = models.CharField(max_length=25)
# 
# class Brand(models.Model):
#     name = models.CharField(max_length=25)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# Path: diag_app/models.py
# class Model(models.Model):
#     name = models.CharField(max_length=40)
#     brand = models.ForeignKey(Brand)
#     year = models.IntegerField(default=0)
# 
#     def __repr__(self):
#         return str(self.name)
# 
# class Problem_Model(models.Model):
#     problem = models.ForeignKey(Problem)
#     model = models.ForeignKey(Model)
# 
# class Commit(models.Model):
#     solution = models.ForeignKey(Solution, related_name='commits')
#     tech = models.ForeignKey(Tech)
#     posted = models.DateTimeField(auto_now=True)
#     text = models.TextField(max_length=200)
# 
# class Notification(models.Model):
#     tech = models.ForeignKey(Tech, related_name='techs')
#     message = models.CharField(max_length=20)
#     # is this the best way to link notifications to events?
#     solution = models.ForeignKey(Solution, related_name='solution',null=True)
#     commit = models.ForeignKey(Commit, related_name='commit',null=True)
#     posted = models.DateTimeField(auto_now=True)


# Path: diag_app/serializers.py
from .models import Vote, Problem, Solution, Tech, Rating, System, Brand
from .models import Model, Problem_Model, Commit, Notification
from django.contrib.auth.models import User
from rest_framework import serializers
from django.contrib.auth import login


class CommitSerializer(serializers.ModelSerializer):

    class Meta:
        model = Commit
        fields = ['id', 'solution', 'tech', 'posted', 'text', 'url']


class VoteSerializer(serializers.ModelSerializer):

    class Meta:
        model = Vote
        fields = "__all__"


class SolutionGetSerializer(serializers.ModelSerializer):
    votes = VoteSerializer(many=True, read_only=True)
    commits = CommitSerializer(many=True, read_only=True)
    tech = TechGetSerializer(many=False, read_only=True)

    class Meta:
        model = Solution
        fields = ['id', 'description', 'time_required', 'parts_cost',
                  'problem', 'tech', 'posted', 'score', 'commits',
                  'votes', 'url']


class SolutionPostSerializer(serializers.ModelSerializer):

    class Meta:

        model = Solution