import pytest
from django.contrib.auth.models import Group

from rcr.models import Item, Level, OncologyCategory, Outcome, OutcomeReason, RadiologyCategory

@pytest.fixture
def create_superuser(db, django_user_model):
    return django_user_model.objects.create_superuser(
        "admin", "ross@xkjq.uk", "adminpassword"
    )

@pytest.fixture
def create_cid_manager(db, django_user_model):
    user = django_user_model.objects.create_user(
        "cid_user", "cid@user.com", "password1234"
    )
    g = Group.objects.create(name="cid_user_manager")
    g.save()
    user.groups.add(g)
    return user

@pytest.fixture
def create_groups(db):
    Group.objects.get_or_create(name="rcr_radiology_assessor")
    Group.objects.get_or_create(name="rcr_oncology_assessor") 
    Group.objects.get_or_create(name="rcr_assessor") 


@pytest.fixture
def create_radiology_user(db, django_user_model, create_groups):
    user = django_user_model.objects.create_user(
        "rad", "rad@user.com", "password1234", first_name="Radiology", last_name="User"
    )
    user.groups.add(Group.objects.get(name="rcr_radiology_assessor"))
    return user

@pytest.fixture
def create_oncology_user(db, django_user_model, create_groups):
    user = django_user_model.objects.create_user(
        "onc", "onc@user.com", "password1234", first_name="Oncology", last_name="User"
    )
    user.groups.add(Group.objects.get(name="rcr_oncology_assessor"))
    return user

@pytest.fixture
def create_item(db, create_radiology_category, create_oncology_category, create_outcome, create_outcome_reason, create_level):
    item =  Item.objects.create(
        name="Test Item",
        description="Test Description",
        content_type="Test Content Type",
        number_of_items=1,
        specialty="Test Specialty",
        access_count=1,
        targeted_to_group="Test Group",
        review_link="Test Review Link",
        review_link_password="Test Password",
        rcr_platform_id="Test Platform ID",
        #radiology_category=create_radiology_category,
        oncology_category=create_oncology_category,
        outcome=create_outcome,
        outcome_reason=create_outcome_reason,
        outcome_free_text="Test Outcome Free Text",
        comments="Test Comments",
        needs_review=True,
        completed_radiology=True,
        completed_oncology=True
    )

    item.level.add(create_level)
    item.radiology_categories.add(create_radiology_category)
    return item

@pytest.fixture
def create_level(db):
    return Level.objects.create(name="Test Level")

@pytest.fixture
def create_radiology_category(db):
    return RadiologyCategory.objects.create(name="Test Radiology Category")

@pytest.fixture
def create_oncology_category(db):
    return OncologyCategory.objects.create(name="Test Oncology Category")

@pytest.fixture
def create_outcome(db):
    return Outcome.objects.create(name="Test Outcome")

@pytest.fixture
def create_outcome_reason(db):
    return OutcomeReason.objects.create(reason="Test Outcome Reason")