export function mindspaceFlags(env = process.env) {
  const enabled = env.MINDSPACE_ENABLED !== 'false';
  return {
    mindspace_enabled: enabled,
    mindspace_upload_enabled: enabled && env.MINDSPACE_UPLOAD_ENABLED !== 'false',
    mindspace_publish_enabled: enabled && env.MINDSPACE_PUBLISH_ENABLED === 'true',
    mindspace_private_enabled: enabled && env.MINDSPACE_PRIVATE_ENABLED !== 'false',
    mindspace_agent_jobs_enabled: enabled && env.MINDSPACE_AGENT_JOBS_ENABLED === 'true',
  };
}

export function assertMindSpaceRoute(flags, route) {
  if (!flags.mindspace_enabled) {
    throw Object.assign(new Error('MindSpace 功能未启用'), { code: 'feature_disabled' });
  }
  if (route === 'upload' && !flags.mindspace_upload_enabled) {
    throw Object.assign(new Error('上传功能未启用'), { code: 'feature_disabled' });
  }
  if (route === 'agent' && !flags.mindspace_agent_jobs_enabled) {
    throw Object.assign(new Error('Agent 任务功能未启用'), { code: 'feature_disabled' });
  }
}
