/**
 * FF AI Agent Personas API Client.
 * Backend: /api/v1/agent/personas  (含系统预设 + 用户自创；DELETE 系统预设软隐藏)
 * 来源判定：systemKey 非空 = 系统预设；createdById 非空 = 用户自创。
 */

import { createCrudClient } from './_crud-factory';

export interface AgentPersona {
  id: string;
  organizationId: string;
  createdById: string | null;
  systemKey: string | null;
  name: string;
  icon: string | null;
  description: string | null;
  instructions: string | null;
  allowedTools: string[];
  enabled: boolean;
  createdAt: string;
  updatedAt: string;
}

export interface CreateAgentPersonaInput {
  name: string;
  icon?: string;
  description?: string;
  instructions?: string;
  allowedTools?: string[];
}

export interface UpdateAgentPersonaInput {
  name?: string;
  icon?: string;
  description?: string;
  instructions?: string;
  allowedTools?: string[];
  enabled?: boolean;
}

export function isSystemPersona(p: AgentPersona): boolean {
  return p.createdById === null && p.systemKey !== null;
}

const client = createCrudClient<
  AgentPersona,
  CreateAgentPersonaInput,
  UpdateAgentPersonaInput,
  { ok: true; soft: boolean }
>('/agent/personas');

export const listAgentPersonas = () => client.list();
export const createAgentPersona = client.create;
export const updateAgentPersona = client.update;
export const deleteAgentPersona = client.remove;
