import {
  MOCK_ACCESS_TOKEN,
  MOCK_API_PRODUCT,
  MOCK_API_PRODUCT_LIST_RESPONSE,
  MOCK_APPLICATION_DETAIL,
  MOCK_APPLICATION_LIST_RESPONSE,
  MOCK_APPLICATION_REQUEST,
  MOCK_AUTH_FULL_INFO,
  MOCK_AUTH_INFO_BASE,
  MOCK_CHANGE_PASSWORD_REQUEST,
  MOCK_PROFILE_DETAIL,
  MOCK_PROFILE_USER_INFO_REQUEST,
  MOCK_SIGN_IN_REQUEST,
  MOCK_SIGN_UP_REQUEST,
  MOCK_SUPPORT_ITEM,
  MOCK_SUPPORT_LIST,
  MOCK_THROTTLING_POLICIES,
} from './index'

describe('_tests_/mocks — export contract', () => {
  describe('auth fixtures', () => {
    it('MOCK_ACCESS_TOKEN has JWT shape (header.payload.sig)', () => {
      const parts = MOCK_ACCESS_TOKEN.split('.')
      expect(parts).toHaveLength(3)
    })

    it('MOCK_AUTH_INFO_BASE exposes OAuth-style token fields', () => {
      expect(MOCK_AUTH_INFO_BASE.access_token).toBeTruthy()
      expect(MOCK_AUTH_INFO_BASE.refresh_token).toBeTruthy()
      expect(MOCK_AUTH_INFO_BASE.expires_in).toEqual(expect.any(Number))
    })

    it('MOCK_AUTH_FULL_INFO.user matches decoded-user contract', () => {
      expect(MOCK_AUTH_FULL_INFO.user.sub).toBe('user123')
      expect(MOCK_AUTH_FULL_INFO.user.exp).toEqual(expect.any(Number))
    })

    it('MOCK_SIGN_UP_REQUEST pairs password fields for signup UI fixtures', () => {
      expect(MOCK_SIGN_UP_REQUEST.password).toBe(
        MOCK_SIGN_UP_REQUEST.confirmPassword,
      )
      expect(MOCK_SIGN_UP_REQUEST.email).toMatch(/@/)
    })

    it('MOCK_SIGN_IN_REQUEST uses credential-shaped fields', () => {
      expect(MOCK_SIGN_IN_REQUEST.username).toMatch(/@/)
      expect(MOCK_SIGN_IN_REQUEST.password).toBeTruthy()
    })
  })

  describe('application fixtures', () => {
    it('MOCK_APPLICATION_DETAIL identifies application', () => {
      expect(MOCK_APPLICATION_DETAIL.applicationId).toBe('app-123')
    })

    it('MOCK_APPLICATION_REQUEST has human-readable name', () => {
      expect(MOCK_APPLICATION_REQUEST.name).toBe('New Application')
    })

    it('MOCK_THROTTLING_POLICIES is non-empty list with policy name', () => {
      expect(MOCK_THROTTLING_POLICIES.length).toBeGreaterThan(0)
      expect(MOCK_THROTTLING_POLICIES[0]).toEqual(
        expect.objectContaining({ name: '10PerMin' }),
      )
    })

    it('MOCK_APPLICATION_LIST_RESPONSE.data.list has first item name', () => {
      expect(MOCK_APPLICATION_LIST_RESPONSE.data.list[0].name).toBe('Test App')
    })
  })

  describe('profile fixtures', () => {
    it('MOCK_PROFILE_DETAIL matches company profile shape', () => {
      expect(MOCK_PROFILE_DETAIL.company_name).toBe('Company Ltd')
    })

    it('MOCK_PROFILE_USER_INFO_REQUEST includes phone', () => {
      expect(MOCK_PROFILE_USER_INFO_REQUEST.phone).toMatch(/^0[0-9]+$/)
    })

    it('MOCK_CHANGE_PASSWORD_REQUEST targets password rotation', () => {
      expect(MOCK_CHANGE_PASSWORD_REQUEST.newPassword).toMatch(/[A-Z]/)
      expect(MOCK_CHANGE_PASSWORD_REQUEST.newPassword).toMatch(/[0-9]/)
    })
  })

  describe('support fixtures', () => {
    it('MOCK_SUPPORT_ITEM is FAQ-like with id and text', () => {
      expect(MOCK_SUPPORT_ITEM.id).toBeTruthy()
      expect(MOCK_SUPPORT_ITEM.question).toContain('password')
    })

    it('MOCK_SUPPORT_LIST mirrors single-item array contract', () => {
      expect(MOCK_SUPPORT_LIST).toHaveLength(1)
      expect(MOCK_SUPPORT_LIST[0]).toBe(MOCK_SUPPORT_ITEM)
    })
  })

  describe('api-product fixtures', () => {
    it('MOCK_API_PRODUCT has stable id', () => {
      expect(MOCK_API_PRODUCT.id).toBe('api-1')
    })

    it('MOCK_API_PRODUCT_LIST_RESPONSE nests list under data', () => {
      expect(MOCK_API_PRODUCT_LIST_RESPONSE.data.list[0].name).toBe(
        'Payment API',
      )
    })
  })
})
