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([])
  experiences   VoiceExperience[]
  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?
  sessions       UserSession[]
  loginRequests  TelegramLoginRequest[]
  voiceExperiences VoiceExperience[]
  createdAt      DateTime          @default(now())
  updatedAt      DateTime          @updatedAt
}

model UserSession {
  id        String   @id @default(cuid())
  tokenHash String   @unique
  userId    String
  user      User     @relation(fields: [userId], references: [id])
  expiresAt DateTime
  createdAt DateTime @default(now())
}

model TelegramLoginRequest {
  id                String   @id @default(cuid())
  tokenHash         String   @unique
  status            String   @default("PENDING")
  sessionToken      String?
  telegramChatId    String?
  telegramMessageId Int?
  userId            String?
  user              User?    @relation(fields: [userId], references: [id])
  expiresAt         DateTime
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt
}

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
  status           VoiceExperienceStatus @default(UPLOADED)
  transcript       String?
  analysis         Json?
  createdAt        DateTime              @default(now())
  updatedAt        DateTime              @updatedAt
}
