from django.db import models

from basic.models import Language
from user.models import Parent


class Community(models.Model):
    keyName = models.TextField(null=True, blank=True)
    createdDate = models.DateTimeField(null=True, blank=True)
    updatedDate = models.DateTimeField(null=True, blank=True)


class CommunityLanguage(models.Model):
    name = models.TextField(null=True, blank=True)
    createdDate = models.DateTimeField(null=True, blank=True)
    updatedDate = models.DateTimeField(null=True, blank=True)
    languageId = models.ForeignKey(
        Language,
        on_delete=models.CASCADE,
        related_name="language_communitylanguage",
    )
    communityId = models.ForeignKey(
        Community,
        on_delete=models.CASCADE,
        related_name="community_communitylanguage",
    )


class CommunityCategory(models.Model):
    keyName = models.TextField(null=True, blank=True)
    createdDate = models.DateTimeField(null=True, blank=True)
    updatedDate = models.DateTimeField(null=True, blank=True)


class CommunityCategoryLanguage(models.Model):
    name = models.TextField(null=True, blank=True)
    createdDate = models.DateTimeField(null=True, blank=True)
    updatedDate = models.DateTimeField(null=True, blank=True)
    languageId = models.ForeignKey(
        Language,
        on_delete=models.CASCADE,
        related_name="language_communitycategorylanguage",
    )
    communityCategoryId = models.ForeignKey(
        CommunityCategory,
        on_delete=models.CASCADE,
        related_name="communitycategory_communitycategorylanguage",
    )


class SocialAccountCommunity(models.Model):
    isSelected = models.BooleanField(default=False)
    createdDate = models.DateTimeField(null=True, blank=True)
    updatedDate = models.DateTimeField(null=True, blank=True)
    parentId = models.ForeignKey(
        Parent,
        on_delete=models.CASCADE,
        related_name="parent_socialaccountcommunity",
    )
    communityId = models.ForeignKey(
        Community,
        on_delete=models.CASCADE,
        related_name="community_socialaccountcommunity",
    )


class Post(models.Model):
    description = models.TextField()
    createdDate = models.DateTimeField()
    updatedDate = models.DateTimeField()
    socialAccountCommunityId = models.ForeignKey(
        SocialAccountCommunity,
        on_delete=models.CASCADE,
        related_name="socialaccountcommunity_post",
    )
    communityId = models.ForeignKey(
        Community,
        on_delete=models.CASCADE,
        related_name="community_post",
    )
    communityCategoryId = models.ForeignKey(
        CommunityCategory,
        on_delete=models.CASCADE,
        related_name="communitycategory_post",
    )


class Comment(models.Model):
    description = models.TextField()
    createdDate = models.DateTimeField()
    updatedDate = models.DateTimeField()
    socialAccountCommunityId = models.ForeignKey(
        SocialAccountCommunity,
        on_delete=models.CASCADE,
        related_name="socialaccountcommunity_comment",
    )
    postId = models.ForeignKey(
        Post,
        on_delete=models.CASCADE,
        related_name="post_comment",
    )


class PostSave(models.Model):
    createdDate = models.DateTimeField()
    updatedDate = models.DateTimeField()
    socialAccountCommunityId = models.ForeignKey(
        SocialAccountCommunity,
        on_delete=models.CASCADE,
        related_name="socialaccountcommunity_postsave",
    )
    postId = models.ForeignKey(
        Post,
        on_delete=models.CASCADE,
        related_name="post_postsave",
    )


class PostLike(models.Model):
    createdDate = models.DateTimeField()
    updatedDate = models.DateTimeField()
    socialAccountCommunityId = models.ForeignKey(
        SocialAccountCommunity,
        on_delete=models.CASCADE,
        related_name="socialaccountcommunity_postlike",
    )
    postId = models.ForeignKey(
        Post,
        on_delete=models.CASCADE,
        related_name="post_postlike",
    )
