/// <reference types="vitest/globals" />

const turboModuleGetMock = vi.fn();

vi.mock('react-native', () => ({
  TurboModuleRegistry: {
    get get() {
      return turboModuleGetMock;
    },
  },
}));

describe('NativeScreenshotProtection', () => {
  beforeEach(() => {
    vi.resetModules();
  });

  describe('when the TurboModuleRegistry resolves the native module', () => {
    const resolvedModule = { setEnabled: vi.fn() };

    beforeEach(() => {
      turboModuleGetMock.mockReturnValue(resolvedModule);
    });

    it('should expose the resolved module as the default export', async () => {
      const imported = await import('./NativeScreenshotProtection');

      expect(imported.default).toBe(resolvedModule);
    });

    it("should look up the native module under the 'DynamicClientScreenshotProtection' key that matches the iOS and Android registration", async () => {
      await import('./NativeScreenshotProtection');

      expect(turboModuleGetMock).toHaveBeenCalledWith(
        'DynamicClientScreenshotProtection'
      );
    });

    it('should resolve the native module exactly once at import time', async () => {
      await import('./NativeScreenshotProtection');

      expect(turboModuleGetMock).toHaveBeenCalledOnce();
    });
  });

  describe('when the TurboModuleRegistry cannot resolve the native module', () => {
    beforeEach(() => {
      turboModuleGetMock.mockReturnValue(null);
    });

    it('should expose null as the default export so consumers can surface a linking error', async () => {
      const imported = await import('./NativeScreenshotProtection');

      expect(imported.default).toBeNull();
    });
  });
});
