"""This module holds the factories for the ``workshops`` app."""

import factory
import factory.django

from mtp.apps.accounts.factories import TraineeFactory
from mtp.apps.trainings.factories import TrainingFactory

from .models import (
    Workshop,
    WorkshopStepImage,
    WorkshopStepQuestion,
    WorkshopStepQuestionAnswer,
    WorkshopStepQuestionUserAnswer
)


class WorkshopFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = Workshop

    name = factory.Sequence(lambda n: 'Quiz-%d' % n)
    training = factory.SubFactory(TrainingFactory)


class AssessingWorkshopFactory(WorkshopFactory):
    is_assessing = True


class WorkshopStepImageFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = WorkshopStepImage

    image = factory.django.ImageField(filename='WorkshopStepImage.jpg', format='PNG')


class WorkshopStepQuestionFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = WorkshopStepQuestion

    title = factory.Sequence(lambda n: 'Question-%d' % n)


class WorkshopStepQuestionAnswerFactory(factory.django.DjangoModelFactory):

    label = factory.Sequence(lambda n: 'Answer-%d' % n)

    class Meta:
        model = WorkshopStepQuestionAnswer


class WorkshopStepQuestionUserAnswerFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = WorkshopStepQuestionUserAnswer

    user = factory.SubFactory(TraineeFactory)
    question = factory.SubFactory(WorkshopStepQuestionFactory)
    answer = factory.SubFactory(WorkshopStepQuestionAnswerFactory)
    text = "This is an answer."
