import { listWorkOrderShares, type WorkOrderRow } from '../../repositories/worker-platform/index.js'

export async function resolveWorkOrderRealtimeWorkerIds(workOrder: WorkOrderRow) {
  const shares = await listWorkOrderShares(workOrder.id)
  return [Number(workOrder.assigned_worker_id), ...shares.map((share) => Number(share.worker_id))]
    .filter((workerId) => Number.isInteger(workerId) && workerId > 0)
    .filter((workerId, index, values) => values.indexOf(workerId) === index)
}
