export enum FactEntityScope {
  ORG = 'org',
  USER = 'user',
  INTEGRATION = 'integration'
}

export enum FactAccessType {
  ALWAYS_INJECT = 'always_inject', // Core memory - always in system prompt
  ON_DEMAND = 'on_demand' // Skills - LLM retrieves via tool call
}

export enum FactCreatedSource {
  MANUAL = 'manual',
  AGENT = 'agent'
}

export interface FactDto {
  id: string;
  name: string;
  description: string;
  content: string;
  metadata?: Record<string, unknown>;
  entityScope: FactEntityScope;
  entityId: string;
  accessType: FactAccessType;
  isEnabled: boolean;
  isApproved: boolean;
  approvedBy?: string;
  createdBy?: string;
  createdSource?: FactCreatedSource;
  createdAt: string;
  updatedAt: string;
}

/**
 * FactListQuery for Socket RPC protocol.
 *
 * NOTE: This type is intentionally duplicated from @superblocksteam/schemas to avoid
 * a circular dependency. The schemas package cannot depend on shared, and the socket
 * protocol in shared needs this type. Keep in sync with packages/schemas/src/schemas/FactListQuery.ts.
 */
export type FactListQuery = {
  entityScope?: FactEntityScope;
  entityId?: string;
  accessType?: FactAccessType;
  isEnabled?: boolean;
  limit?: number;
  offset?: number;
  sortBy?: 'name' | 'created_at' | 'updated_at';
  sortOrder?: 'asc' | 'desc';
  search?: string;
};

export interface ListFactsResponse {
  facts: FactDto[];
}

/**
 * FactCreate for Socket RPC protocol.
 *
 * NOTE: This type is intentionally duplicated from @superblocksteam/schemas to avoid
 * a circular dependency. The schemas package cannot depend on shared, and the socket
 * protocol in shared needs this type. Keep in sync with packages/schemas/src/schemas/FactCreate.ts.
 */
export type FactCreate = {
  name: string;
  description: string;
  content: string;
  metadata?: Record<string, unknown>;
  entityScope: FactEntityScope;
  entityId: string;
  accessType?: FactAccessType;
  createdSource?: FactCreatedSource;
};
