export type Visibility = 'public' | 'friends' | 'private'
export type FeedChannel = 'feed' | 'nearby' | 'follow'
export type MessageTab = 'all' | 'unread'

export interface GeoPoint {
  latitude: number
  longitude: number
}

export interface MediaAsset {
  id: string
  fileId?: string
  url?: string
  color?: string
  type: 'image' | 'video'
}

export interface UserProfile {
  _id: string
  openid?: string
  nickname: string
  handle: string
  avatarKey: string
  avatarUrl?: string
  profileCompleted?: boolean
  location: string
  yearsWithPets: number
  level: number
  bio: string
  verified: boolean
  stats: {
    posts: number
    following: number
    followers: number
  }
  preferences: {
    notifications: boolean
    nearbyVisible: boolean
  }
}

export interface Pet {
  _id: string
  ownerId: string
  name: string
  species: 'dog' | 'cat' | 'other'
  breed: string
  ageText: string
  birthDate?: string
  distanceText?: string
  avatarKey: string
  photoKey: string
  photoUrl?: string
  tags: string[]
  mood?: string
  location?: GeoPoint
  online?: boolean
}

export interface Post {
  _id: string
  author: {
    id: string
    name: string
    avatarKey: string
    avatarUrl?: string
    // Real presence: author was recently active & visible in 附近 (see nearby).
    online?: boolean
  }
  pet: {
    name: string
    breed: string
    tone?: 'purple' | 'green' | 'gold'
  }
  body: string
  topics: string[]
  media?: string[]
  mediaTone: 'pet-1' | 'pet-2' | 'pet-3'
  sticker?: string
  locationText: string
  timeText: string
  visibility?: Visibility
  counts: {
    likes: number
    comments: number
  }
  likedByMe: boolean
}

export interface PostComment {
  _id: string
  author: {
    id: string
    name: string
    avatarKey: string
    avatarUrl?: string
  }
  content: string
  timeText: string
}

export interface NearbyPet extends Pet {
  ownerName?: string
  isMine?: boolean
  isFollowing?: boolean
  isFriend?: boolean
  likedByMe?: boolean
  // Real map coordinates — the owner's latest reported location.
  latitude?: number
  longitude?: number
}

export interface ActiveUser {
  id: string
  name: string
  avatarKey: string
  avatarUrl?: string
  live?: boolean
}

export interface Conversation {
  _id: string
  type: 'single' | 'system'
  title: string
  petName?: string
  avatarKey: string
  avatarUrl?: string
  preview: string
  timeText: string
  unreadCount: number
  pinned?: boolean
  muted?: boolean
  online?: boolean
}

export interface SocialUser {
  id: string
  name: string
  handle?: string
  avatarKey: string
  avatarUrl?: string
  bio?: string
  isFollowing: boolean
  isFriend: boolean
}

export interface FollowCounts {
  following: number
  followers: number
  friends: number
}

export interface ChatPeer {
  id: string
  name: string
  avatarKey: string
  avatarUrl?: string
}

export interface ChatMessage {
  _id: string
  fromMe: boolean
  content: string
  type: string
  fileId?: string
  assetState?: 'ready' | 'unresolved'
  createdAt: number
  timeText: string
}

export interface PublishDraft {
  content: string
  topics: string[]
  media: MediaAsset[]
  petId?: string | null
  petSelectionExplicit?: boolean
  locationText?: string
  latitude?: number
  longitude?: number
  visibility: Visibility
  saveDraft: boolean
}
