import factory
import factory.fuzzy

from mtp.apps.accounts.factories import JobProfileFactory, TraineeFactory
from mtp.apps.trainings.factories import TrainingSessionFactory

from ..models import (
    Competency,
    CompetencyTree,
    CompetencyTreeUserScore,
    CompetencyUserScore,
    Dimension,
    DimensionUserScore,
)


class CompetencyTreeFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = CompetencyTree

    name = factory.Sequence(lambda n: 'tree-%d' % n)
    job_profile = factory.SubFactory(JobProfileFactory)


class CompetencyTreeUserScoreFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = CompetencyTreeUserScore

    tree = factory.SubFactory(CompetencyTreeFactory)
    user = factory.SubFactory(TraineeFactory)


class CompetencyFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = Competency

    name = factory.Sequence(lambda n: 'competency-%d' % n)
    code = factory.Sequence(lambda n: 'COM-%d' % n)
    tree = factory.SubFactory(CompetencyTreeFactory)


class GhostCompetencyFactory(CompetencyFactory):
    is_ghost = True


class UserScoreFactory(factory.django.DjangoModelFactory):

    session = factory.SubFactory(TrainingSessionFactory)
    user = factory.SubFactory(TraineeFactory)
    score = factory.fuzzy.FuzzyInteger(50)  # Random integer between 0 and 50


class CompetencyUserScoreFactory(UserScoreFactory):

    class Meta:
        model = CompetencyUserScore

    competency = factory.SubFactory(CompetencyFactory)


class DimensionFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = Dimension

    name = factory.Sequence(lambda n: 'dimension-%d' % n)
    code = factory.Sequence(lambda n: 'DIM-%d' % n)
    competency = factory.SubFactory(CompetencyFactory)


class DimensionUserScoreFactory(UserScoreFactory):

    class Meta:
        model = DimensionUserScore

    dimension = factory.SubFactory(DimensionFactory)
