// ─── Entra org tenant — staff only ───────────────────────────────────────────
const TENANT_ID = 'f56a3c51-9b5c-4356-920f-b4dcf932a96b'; // positivespend tenant

// AdPlatform Admin SPA app registration — registered in positivespend tenant
// Portal → App Registrations → AdPlatform Admin SPA → Application (client) ID
const CLIENT_ID = '6873dee3-aff8-405d-9bc1-120c20794f98'; // TODO: replace after creating Admin SPA registration

const AUTHORITY = `https://login.microsoftonline.com/${TENANT_ID}`;

// ─── Management API resource ──────────────────────────────────────────────────
// Audience for access tokens sent to Management API.
// Scope requests this audience so tokens carry the `roles` claim.
export const MGMT_APP_ID    = 'af95fa13-2ef4-4911-b137-7acc6a784cfa'; // AdPlatform Management Staff API
export const MGMT_SCOPE     = `api://${MGMT_APP_ID}/access_as_user`;

// ─── URLs ─────────────────────────────────────────────────────────────────────
export const MANAGEMENT_URL   = 'https://mgmt.positivespend.com';
export const REGISTRATION_URL = 'https://regapi.positivespend.com';

// ─── MSAL configuration ───────────────────────────────────────────────────────
export const msalConfig = {
  auth: {
    clientId: CLIENT_ID,
    authority: AUTHORITY,
    redirectUri: window.location.origin,
    postLogoutRedirectUri: window.location.origin,
    knownAuthorities: ['login.microsoftonline.com'],
    navigateToLoginRequestUrl: true,
  },
  cache: {
    cacheLocation: 'localStorage',
    storeAuthStateInCookie: false,
  },
  system: {
    loggerOptions: {
      loggerCallback: (level, message, containsPii) => {
        if (containsPii) return;
        if (level === 0) console.error(message);
        else if (level === 1) console.warn(message);
      },
      logLevel: 1, // warn + error only
    },
  },
};

// Login request — include Management API scope so access tokens carry `roles`
export const loginRequest = {
  scopes: ['openid', 'profile', 'email', MGMT_SCOPE],
  prompt: 'select_account',
};

// ─── Aliases ──────────────────────────────────────────────────────────────────
export const MGMT_BASE = MANAGEMENT_URL;
