import factory
import factory.fuzzy
import pytz

from newsreader.accounts.tests.factories import UserFactory
from newsreader.news.collection.reddit import REDDIT_API_URL
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=pytz.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")


class RedditPostFactory(PostFactory):
    url = factory.fuzzy.FuzzyText(length=10, prefix=f"{REDDIT_API_URL}/")
    rule = factory.SubFactory(
        "newsreader.news.collection.tests.factories.SubredditFactory"
    )
