from django.db import models
from django.contrib.auth.models import User

from cloudinary.models import CloudinaryField

POST_TAGS = (
    ("TECHNOLOGY", "TECHNOLOGY"),
    ("AGRICULTURE", "AGRICULTURE"),
    ("POLITICS", "POLITICS"),
    ("EDUCATION", "EDUCATION"),
    ("HEALTH", "HEALTH"),
    ("ECONOMICS", "ECONOMICS"),
    ("LIFESTYLE", "LIFESTYLE"),
    ("ENVIRONMENT", "ENVIRONMENT"),
    ("CULTURE", "CULTURE"),
    ("INNOVATION", "INNOVATION"),
    ("SCIENCE", "SCIENCE"),
    ("CONFLICT", "CONFLICT"),
    ("OTHER", "OTHER")
)


sCHOLARSHIPS_TYPE = (
    ("BSC", "BSC"),
    ("MSC", "MSC"),
    ("PHD", "PDD"),
    ("INTERNSHIP", "INTERNSHIP"),
    ("FELLOWSHIP", "FELLOWSHIP"),
    ("OTHER", "OTHER")
    
)


VILLAGES = (
    ("AKANATOR", "AKANATOR"),
    ("AMIKWE", "AMIKWE"),
    ("ATURIA", "ATURIA"),
    ("ORENJA", "ORENJA")
)


CANDIDATE_CATEGORY = (
    # ("JUNIOR SECONDARY", "JUNIOR SECONDARY"),
    ("SENIOR SECONDARY", "SENIOR SECONDARY"),
)


class Post(models.Model):
    post_tag        = models.CharField(max_length=20, blank=True, null=True, choices=POST_TAGS)
    title           = models.CharField(max_length=200)
    sub_title_1     = models.CharField(max_length=200, blank=True, null=True)
    posted_by       = models.ForeignKey(User, related_name='poster', on_delete=models.CASCADE)
    date            = models.DateField(auto_now_add=True)
    post_image_1    = CloudinaryField("Epoo/posts-images/")
    post_image_2    = CloudinaryField("Epoo/posts-images/")
    post_image_3    = CloudinaryField("Epoo/posts-images/")
    paragraph_1     = models.TextField(max_length=350)
    
    sub_title_2     = models.CharField(max_length=200, help_text="This is the subtitle for the 3 paragraphs below")
    paragraph_2     = models.TextField(max_length=350)
    paragraph_3     = models.TextField(max_length=350)
    paragraph_4     = models.TextField(max_length=350)
    
    sub_title_3     = models.CharField(max_length=200, help_text="This is the subtitle for the last 4 paragraphs below")
    paragraph_5     = models.TextField(max_length=350)
    paragraph_6     = models.TextField(max_length=350)
    paragraph_7     = models.TextField(max_length=350)
    paragraph_8     = models.TextField(max_length=350)
    views           = models.PositiveBigIntegerField(default=0, editable=False)
    
    class Meta:
        ordering = ("-id",)
    
    def __str__(self):
        return f"{self.title} {self.post_tag}"
    
    
    
class PostEngagement(models.Model):
    post            = models.ForeignKey(Post, related_name="posts_comment", on_delete=models.CASCADE)
    comments        = models.TextField()
    
    def __str__(self):
        return f"Post engagements for {self.post.title}"
    


class Scholarship(models.Model):
    Scholarship_type    = models.CharField(max_length=20, choices=sCHOLARSHIPS_TYPE)
    title               = models.CharField(max_length=200)
    date                = models.DateField(auto_now_add=True)
    description         = models.TextField()
    scholarship_image   = CloudinaryField("Epoo/scholarship-images/")
    scholarship_link    = models.URLField(help_text="Enter the link to the Scholarship here")
    
    def __str__(self):
        return f"{self.Scholarship_type} - {self.title}"
    

class Candidate(models.Model):
    name                = models.CharField(max_length=255)
    village             = models.CharField(max_length=20, choices=VILLAGES)
    year_participated   = models.PositiveIntegerField(default=2_000)
    school              = models.CharField(max_length=200)
    category            = models.CharField(max_length=20, choices=CANDIDATE_CATEGORY)
    score               = models.PositiveIntegerField(default=0)
    candidate_image     = CloudinaryField("Epoo/candidate-images/")
    description         = models.TextField(max_length=300, help_text="Maximum character is 300")
    
    def __str__(self):
        return f"{self.name} - {self.category}"
    

class Team(models.Model):
    name                = models.CharField(max_length=20)
    role                = models.CharField(max_length=50)
    website             = models.URLField(blank=True, null=True)
    linkedin_profile    = models.URLField(blank=True, null=True)
    facebook_profile    = models.URLField(blank=True, null=True)
    twitter_profile     = models.URLField(blank=True, null=True)
    youtube_channel     = models.URLField(blank=True, null=True)
    email               = models.EmailField(blank=True, null=True)
    phone               = models.CharField(max_length=20, blank=True, null=True, help_text="Include country code eg. +234")
    description         = models.TextField(max_length=250)
    profile_photo       = CloudinaryField("Epoo/profile-images/")
    
    def __str__(self):
        return f"{self.name} - {self.role}"
    
    

class SubscriberEmail(models.Model):
    email               = models.EmailField(max_length=255)
    
    def __str__(self):
        return self.email