import { UserRole } from '@prisma/client';
import { FEATURE_CATALOG, FeatureKey } from './feature-catalog';

function defaultRolesFor(feature: FeatureKey) {
  const definition = FEATURE_CATALOG.find((item) => item.key === feature);
  if (!definition) {
    throw new Error(`Missing feature definition: ${feature}`);
  }
  return definition.defaultRoles;
}

describe('feature catalog', () => {
  it('keeps sales admin payment access disabled by default', () => {
    expect(defaultRolesFor(FeatureKey.PAYMENTS_VIEW)).not.toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.PAYMENTS_CONFIRM)).not.toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.PAYMENT_PROVIDERS_VIEW)).not.toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.PAYMENT_PROVIDERS_MANAGE)).not.toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.SALES_PARTNER_EARNINGS_VIEW)).not.toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.SALES_PARTNER_ADMIN_CONTACT)).not.toContain(UserRole.SALES_ADMIN);
  });

  it('allows sales admin to work across estate operations by default', () => {
    expect(defaultRolesFor(FeatureKey.PLATFORM_DASHBOARD)).toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.SALES_PARTNER_PROFILE_VIEW)).toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.ESTATES_VIEW)).toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.ESTATES_MANAGE)).toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.RESIDENTS_VIEW)).toContain(UserRole.SALES_ADMIN);
    expect(defaultRolesFor(FeatureKey.GUARDS_VIEW)).toContain(UserRole.SALES_ADMIN);
  });
});
