from datetime import timezone

import factory
import factory.fuzzy

from newsreader.accounts.tests.factories import UserFactory
from newsreader.news.core.models import Category, Post


class CategoryFactory(factory.django.DjangoModelFactory):
    name = factory.Sequence(lambda n: "Category-{}".format(n))
    user = factory.SubFactory(UserFactory)

    class Meta:
        model = Category


class PostFactory(factory.django.DjangoModelFactory):
    title = factory.Faker("sentence")
    body = factory.Faker("paragraph")
    author = factory.Faker("name")
    publication_date = factory.Faker("date_time_this_year", tzinfo=timezone.utc)
    url = factory.Faker("url")
    remote_identifier = factory.Faker("uuid4")

    rule = factory.SubFactory(
        "newsreader.news.collection.tests.factories.CollectionRuleFactory"
    )

    read = False

    class Meta:
        model = Post


class FeedPostFactory(PostFactory):
    rule = factory.SubFactory("newsreader.news.collection.tests.factories.FeedFactory")
