import { describe, expect, it } from 'vitest'
import { idParamSchema, inviteSchema, roleSchema } from './team.schemas'

describe('team.schemas edge contracts', () => {
  it('accepts only invite payloads with real names, emails and assignable non-owner roles', () => {
    expect(inviteSchema.parse({
      firstName: 'Aya',
      lastName: 'Haddad',
      email: 'aya@example.test',
      role: 'MANAGER',
    })).toEqual({
      firstName: 'Aya',
      lastName: 'Haddad',
      email: 'aya@example.test',
      role: 'MANAGER',
    })

    expect(inviteSchema.safeParse({ firstName: '', lastName: 'Haddad', email: 'aya@example.test', role: 'MANAGER' }).success).toBe(false)
    expect(inviteSchema.safeParse({ firstName: 'Aya', lastName: 'Haddad', email: 'not-email', role: 'MANAGER' }).success).toBe(false)
    expect(inviteSchema.safeParse({ firstName: 'Aya', lastName: 'Haddad', email: 'aya@example.test', role: 'OWNER' }).success).toBe(false)
  })

  it('restricts role changes to operational roles only', () => {
    expect(roleSchema.parse({ role: 'AGENT' })).toEqual({ role: 'AGENT' })
    expect(roleSchema.parse({ role: 'MANAGER' })).toEqual({ role: 'MANAGER' })
    expect(roleSchema.safeParse({ role: 'OWNER' }).success).toBe(false)
    expect(roleSchema.safeParse({ role: 'ADMIN' }).success).toBe(false)
  })

  it('rejects empty team member route params', () => {
    expect(idParamSchema.parse({ id: 'employee_1' })).toEqual({ id: 'employee_1' })
    expect(idParamSchema.safeParse({ id: '' }).success).toBe(false)
  })
})
