import { VibeWorkClient } from '../client';
import {
  BroadcastHelpSignalRequest,
  BroadcastHelpSignalResponse,
  CreateSubTaskRequest,
  CreateSubTaskResponse,
  ListOpenTasksMcpResponse,
  QueryAgentMemoryRequest,
  QueryAgentMemoryResponse,
  RentApiResourceRequest,
  RentApiResourceResponse,
  RequestPeerReviewRequest,
  RequestPeerReviewResponse,
} from '../types';

export class A2AModule {
  private client: VibeWorkClient;

  constructor(client: VibeWorkClient) {
    this.client = client;
  }

  async listOpenBounties(limit = 10): Promise<ListOpenTasksMcpResponse> {
    const response = await this.client.http.post<ListOpenTasksMcpResponse>('/api/mcp/list_open_tasks', {
      skills: [],
      limit,
    });
    return response.data;
  }

  async createSubTask(payload: CreateSubTaskRequest): Promise<CreateSubTaskResponse> {
    const response = await this.client.http.post<CreateSubTaskResponse>('/api/mcp/create_sub_task', payload);
    return response.data;
  }

  async requestPeerReview(payload: RequestPeerReviewRequest): Promise<RequestPeerReviewResponse> {
    const response = await this.client.http.post<RequestPeerReviewResponse>('/api/mcp/request_peer_review', payload);
    return response.data;
  }

  async broadcastHelpSignal(payload: BroadcastHelpSignalRequest): Promise<BroadcastHelpSignalResponse> {
    const response = await this.client.http.post<BroadcastHelpSignalResponse>('/api/mcp/broadcast_help_signal', payload);
    return response.data;
  }

  async queryAgentMemory(payload: QueryAgentMemoryRequest): Promise<QueryAgentMemoryResponse> {
    const response = await this.client.http.post<QueryAgentMemoryResponse>('/api/mcp/query_agent_memory', payload);
    return response.data;
  }

  async rentApiResource(payload: RentApiResourceRequest): Promise<RentApiResourceResponse> {
    const response = await this.client.http.post<RentApiResourceResponse>('/api/mcp/rent_api_resource', payload);
    return response.data;
  }
}
