import { beforeEach, describe, expect, it, vi } from 'vitest'

vi.mock('../../services/teamService', () => ({
  listEmployees: vi.fn(),
  inviteEmployee: vi.fn(),
  updateEmployeeRole: vi.fn(),
  deactivateEmployee: vi.fn(),
  reactivateEmployee: vi.fn(),
  removeEmployee: vi.fn(),
}))

import { listEmployees } from '../../services/teamService'
import { getMembers, getMemberStats } from './team.service'

describe('team.service module facade', () => {
  beforeEach(() => vi.clearAllMocks())

  it('returns the tenant member list without modifying teamService output', async () => {
    const members = [{ id: 'emp_1', role: 'OWNER', isActive: true, invitationStatus: 'accepted' }]
    vi.mocked(listEmployees).mockResolvedValue(members as never)

    await expect(getMembers('company_1')).resolves.toBe(members)
    expect(listEmployees).toHaveBeenCalledWith('company_1')
  })

  it('counts active, pending, and inactive accepted team members explicitly', async () => {
    vi.mocked(listEmployees).mockResolvedValue([
      { id: 'owner_1', isActive: true, invitationStatus: 'accepted' },
      { id: 'manager_1', isActive: true, invitationStatus: 'accepted' },
      { id: 'agent_1', isActive: false, invitationStatus: 'accepted' },
      { id: 'agent_2', isActive: true, invitationStatus: 'pending' },
      { id: 'agent_3', isActive: false, invitationStatus: 'revoked' },
    ] as never)

    await expect(getMemberStats('company_1')).resolves.toEqual({
      total: 5,
      active: 2,
      pending: 1,
      inactive: 1,
    })
  })
})
