import { test, expect } from '@playwright/test';
import { RoleAuthHelper } from '../../helpers/helpers';

test.describe('Department Manager Role', () => {
  test.describe.configure({ mode: 'parallel' });

  test('login succeeds and goes to dashboard', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    expect(page.url()).not.toContain('login');
    expect(page.url()).not.toContain('select-hospital');
  });

  test('cannot access config dashboard', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    await page.goto('/config/');
    const blocked = page.url().includes('command-center') || page.url().includes('analytics') || page.url().toContain('login');
    expect(blocked).toBeTruthy();
  });

  test('can view complaints list', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    const response = await page.goto('/complaints/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can view surveys page', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    const response = await page.goto('/surveys/templates/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can view observations page', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    const response = await page.goto('/observations/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access dashboard', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    const response = await page.goto('/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can view physician ratings', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    const response = await page.goto('/physicians/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access organizations (view-only)', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('dept_manager');

    await page.goto('/organizations/');
    await page.waitForLoadState('domcontentloaded');
    expect(page.url()).not.toContain('login');
  });
});
