from django.test import TestCase
from django.contrib.auth.models import User
from .models import Employee

class EmployeeModelTests(TestCase):
    def setUp(self):
        # Create test user
        self.user = User.objects.create_user(
            username='testuser',
            password='testpass123',
            first_name='Test',
            last_name='User'
        )
        
        # Create test employee
        self.employee = Employee.objects.create(
            user=self.user,
            role='HR',
            basic_pay=5000.00,
            annual_leave_days=24,
            accumulated_leave_days=10
        )

    def test_employee_creation(self):
        """Test that an employee can be created with correct attributes"""
        self.assertEqual(self.employee.user.username, 'testuser')
        self.assertEqual(self.employee.role, 'HR')
        self.assertEqual(self.employee.basic_pay, 5000.00)
        self.assertEqual(self.employee.annual_leave_days, 24)
        self.assertEqual(self.employee.accumulated_leave_days, 10)

    def test_employee_str_representation(self):
        """Test the string representation of Employee model"""
        expected_str = "Test User - Human Resource"
        self.assertEqual(str(self.employee), expected_str)

    def test_employee_roles(self):
        """Test that employees can be created with different roles"""
        roles = {
            'HR': 'Human Resource',
            'EMP': 'Employee',
            'REG': 'Registrar',
            'FIN': 'Finance'
        }
        
        for role_code, role_name in roles.items():
            employee = Employee.objects.create(
                user=User.objects.create_user(
                    username=f'user_{role_code}',
                    password='testpass123'
                ),
                role=role_code,
                basic_pay=4000.00
            )
            self.assertEqual(employee.get_role_display(), role_name)
