import pytest
from django.contrib.auth import get_user_model
from apps.companies.models import Company


@pytest.fixture
def user(db):
    User = get_user_model()
    return User.objects.create_user(email="company@example.com", password="pass123")


@pytest.mark.django_db
class TestCompanyModel:
    def test_create_company(self, user):
        company = Company.objects.create(
            name="Acme Corporation",
            legal_name="Acme Corp Legal Entity",
            industry="technology",
            website="https://acme.com",
            email="contact@acme.com",
            phone="1234567890",
            city="San Francisco",
            country="USA",
            created_by=user
        )
        assert company.name == "Acme Corporation"
        assert company.slug == "acme-corporation"
        assert company.industry == "technology"

    def test_company_slug_auto_generated(self):
        company = Company.objects.create(name="Tech Startup Inc")
        assert company.slug == "tech-startup-inc"

    def test_company_industry_choices(self, user):
        company = Company.objects.create(
            name="Finance Co",
            industry="finance",
            created_by=user
        )
        assert company.industry == "finance"

    def test_company_str(self, user):
        company = Company.objects.create(name="Test Company", created_by=user)
        assert str(company) == "Test Company"

    def test_company_with_tags(self, user):
        company = Company.objects.create(
            name="Tagged Company",
            tags=["partner", "vendor"],
            created_by=user
        )
        assert company.tags == ["partner", "vendor"]

    def test_company_address_fields(self, user):
        company = Company.objects.create(
            name="Global Corp",
            address="123 Main St",
            city="New York",
            country="USA",
            created_by=user
        )
        assert company.address == "123 Main St"
        assert company.city == "New York"
        assert company.country == "USA"
