/** 调用方主体验证（来自可信的 AgentToolContext / AuthenticatedUser）。 */
export interface BusinessContextPrincipal {
  readonly permissions: readonly string[];
  readonly isSuperAdmin: boolean;
}

export type BusinessEntityFieldType = 'string' | 'number' | 'boolean' | 'date' | 'enum';

export interface BusinessEntityField {
  key: string;
  label: string;
  type: BusinessEntityFieldType;
  required?: boolean;
  /** 枚举值来源（如 gender、room.status），供 render_form 生成 options。 */
  enumFrom?: string;
  options?: Array<{ label: string; value: string }>;
  description?: string;
}

export interface BusinessEntityRelation {
  entityKey: string;
  via: string;
  /** 需要该关系已建立的工作流阶段 key。 */
  requiredFor: readonly string[];
}

export interface BusinessEntity {
  key: string;
  name: string;
  description: string;
  searchTool?: string;
  requiredPermissions: readonly string[];
  fields: readonly BusinessEntityField[];
  relations: readonly BusinessEntityRelation[];
}

export interface BusinessWorkflowStage {
  key: string;
  label: string;
  entities: readonly string[];
}

export interface BusinessWorkflowNextStep {
  key: string;
  label: string;
  /** 满足这些阶段完成后才建议该步骤。 */
  after: readonly string[];
  /** 可选权限点，未授权用户不返回该建议。 */
  permission?: string;
}

export interface BusinessWorkflow {
  key: string;
  name: string;
  description: string;
  requiredPermissions: readonly string[];
  stages: readonly BusinessWorkflowStage[];
  /** stageKey -> 前置阶段 key 列表。 */
  prerequisites: Readonly<Record<string, readonly string[]>>;
  nextSteps: readonly BusinessWorkflowNextStep[];
}

export interface BusinessContextResult {
  workflows: readonly BusinessWorkflow[];
  entities: readonly BusinessEntity[];
}
