import {z} from 'zod'

import {CrumbSchema} from './crumbs'
import {PublicProfileSchema} from './friends'
import {CrumbReactionSummarySchema} from './trails'

export const RecommendedCrumbsQuerySchema = z.object({
  lat: z.coerce.number().min(-90).max(90),
  lng: z.coerce.number().min(-180).max(180),
  radiusKm: z.coerce.number().positive().max(50).optional(),
  limit: z.coerce.number().int().positive().max(50).optional(),
})

// one standout crumb per nearby place the viewer's friends have crumbed:
// the place's most-reacted crumb (falling back to the strongest status +
// recency signal), attributed to its author, with reaction tallies
export const RecommendedCrumbSchema = z.object({
  crumb: CrumbSchema,
  author: PublicProfileSchema,
  reactions: z.array(CrumbReactionSummarySchema),
  distanceKm: z.number().nonnegative(),
})

export type RecommendedCrumbsQuery = z.infer<
  typeof RecommendedCrumbsQuerySchema
>
export type RecommendedCrumb = z.infer<typeof RecommendedCrumbSchema>
