/**
 * (share/lib/schema — Zod email/phone validation, messages).
 */
import { validateEmailSchema, validatePhoneSchema } from '../schema'

describe('[share/lib/schema]', () => {
  describe('validateEmailSchema', () => {
    const EmailSchema = validateEmailSchema()

    it('accepts valid email and trims whitespace', () => {
      const result = EmailSchema.safeParse('  dev@company.com  ')
      expect(result.success).toBe(true)
      expect(result.data).toBe('dev@company.com')
    })

    it('rejects invalid email format', () => {
      expect(EmailSchema.safeParse('not-an-email').success).toBe(false)
    })

    it('uses custom message keys when overrides are provided', () => {
      const schema = validateEmailSchema({
        invalid: 'error.reg_ticket.representative_email.invalid',
      })
      const result = schema.safeParse('not-an-email')
      expect(result.success).toBe(false)
      if (!result.success) {
        expect(result.error.issues[0]?.message).toBe(
          'error.reg_ticket.representative_email.invalid'
        )
      }
    })
  })

  describe('validatePhoneSchema', () => {
    const PhoneSchema = validatePhoneSchema()

    it('accepts valid digits-only phone and trims whitespace', () => {
      const result = PhoneSchema.safeParse('  09012345678  ')
      expect(result.success).toBe(true)
      expect(result.data).toBe('09012345678')
    })

    it('rejects non-digit characters', () => {
      expect(PhoneSchema.safeParse('09A123').success).toBe(false)
    })
  })
})
