import { api } from '../../shared/api/client'
import {
  researchSellPolicyRequestSchema,
  researchSellPolicyResponseSchema,
  type ResearchSellPolicyRequest,
  type ResearchSellPolicyResponse
} from './schema'

export interface ResearchSellPolicyCommand {
  request: ResearchSellPolicyRequest
  idempotencyKey: string
}

export async function evaluateResearchSellPolicy(
  command: ResearchSellPolicyCommand
): Promise<ResearchSellPolicyResponse> {
  const request = researchSellPolicyRequestSchema.parse(command.request)
  const { data } = await api.post(
    '/internal/v1/research/sell-policy/evaluate',
    request,
    { headers: { 'Idempotency-Key': command.idempotencyKey } }
  )
  return researchSellPolicyResponseSchema.parse(data)
}
