"""Smoke tests for Contacts models."""
from __future__ import annotations

import pytest

from apps.rims.contacts.models import Contact, ContactGroup


@pytest.mark.django_db
def test_contact_individual_display_name():
    c = Contact(contact_type=Contact.ContactType.INDIVIDUAL, first_name="Jane", last_name="Doe")
    assert str(c) == "Jane Doe"


@pytest.mark.django_db
def test_contact_organisation_display_name():
    c = Contact(contact_type=Contact.ContactType.ORGANISATION, organisation_name="RUFORUM Sec")
    assert str(c) == "RUFORUM Sec"


@pytest.mark.django_db
def test_contact_group_assignment(db):
    group = ContactGroup.objects.create(name="Donors")
    contact = Contact.objects.create(
        contact_type=Contact.ContactType.INDIVIDUAL,
        first_name="Alice",
        last_name="Kato",
        email="alice@example.com",
    )
    contact.groups.add(group)
    assert group in contact.groups.all()
    assert contact in group.contacts.all()


@pytest.mark.django_db
def test_contact_fallback_to_email_when_no_name(db):
    c = Contact.objects.create(email="noname@example.com")
    assert str(c) == "noname@example.com"
