generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

enum VoiceExperienceStatus {
  UPLOADED
  TRANSCRIBING
  TRANSCRIBED
  ANALYZING
  ANALYZED
  FAILED
}

model Place {
  id                        String              @id @default(cuid())
  googlePlaceId             String              @unique
  name                      String
  latitude                  Float
  longitude                 Float
  googlePrimaryType         String?
  googleTypes               String[]            @default([])
  googleBusinessStatus      String?
  googleRating              Float?
  googleUserRatingCount     Int?
  googleRegularOpeningHours Json?
  googleCurrentOpeningHours Json?
  googlePhotos              Json?
  googlePayload             Json?
  googlePayloadFetchedAt    DateTime?
  experiences               VoiceExperience[]
  favoriteUsers             UserFavoritePlace[]
  createdAt                 DateTime            @default(now())
  updatedAt                 DateTime            @updatedAt
}

model User {
  id               String              @id @default(cuid())
  telegramId       String              @unique
  username         String?
  firstName        String?
  lastName         String?
  photoUrl         String?
  languageCode     String?
  isAdmin          Boolean             @default(false)
  voiceExperiences VoiceExperience[]
  favoritePlaces   UserFavoritePlace[]
  createdAt        DateTime            @default(now())
  updatedAt        DateTime            @updatedAt
}

model UserFavoritePlace {
  id        String   @id @default(cuid())
  userId    String
  user      User     @relation(fields: [userId], references: [id])
  placeId   String
  place     Place    @relation(fields: [placeId], references: [id])
  createdAt DateTime @default(now())

  @@unique([userId, placeId])
}

model VoiceExperience {
  id                 String                @id @default(cuid())
  placeId            String
  place              Place                 @relation(fields: [placeId], references: [id])
  userId             String?
  user               User?                 @relation(fields: [userId], references: [id])
  durationSeconds    Int
  audioObjectKey     String
  audioContentBase64 String?
  audioMimeType      String?
  audioAccessToken   String?               @unique
  status             VoiceExperienceStatus @default(UPLOADED)
  transcript         String?
  analysis           Json?
  recordingPayload   Json?
  promptHintsShown   String[]              @default([])
  createdAt          DateTime              @default(now())
  updatedAt          DateTime              @updatedAt
}
