import {z} from 'zod'

import {env} from '../env'

// join tokens are minted as 24 random bytes base64url-encoded (32 chars);
// the range tolerates other lengths without accepting garbage
export const SHARE_TOKEN_REGEX = /^[\w-]{16,128}$/

export const ShareTokenSchema = z.string().regex(SHARE_TOKEN_REGEX)

export const shareLinkUrl = (token: string) =>
  `${env.PUBLIC_API_URL}/trails/join/${token}`
