import { z } from 'zod'
import type { AcqDealRow } from './types'

export interface Action {
  key: string
  label: string
  payloadSchema?: z.ZodTypeAny
}

export interface ActionDef {
  key: string
  label: string
  isAvailableFor: (deal: AcqDealRow) => boolean
  workflowId: string
  payloadSchema?: z.ZodTypeAny
}

type DealActionInput = AcqDealRow & {
  ownership?: 'us' | 'them' | null
  nextAction?: string | null
}

export const SendReplyActionPayloadSchema = z
  .object({
    replyBody: z.string().trim().min(1).max(10000)
  })
  .strict()

export function deriveActions(deal: DealActionInput, actions: ActionDef[] = []): Action[] {
  return actions
    .filter((a) => a.isAvailableFor(deal))
    .map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }))
}

