generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-3.0.x", "debian-openssl-3.0.x"]
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model User {
  id          String        @id @default(uuid())
  googleId    String?       @unique @map("google_id")
  email       String?
  deviceId    String?       @unique @map("device_id")
  phone       String?
  name        String
  city        String?
  avatarText  String?       @map("avatar_text")
  avatarUrl   String?       @map("avatar_url")
  badgeTitle  String?       @map("badge_title")
  createdAt   DateTime      @default(now()) @map("created_at")
  malaRecords MalaRecord[]
  customMantras UserCustomMantra[]

  @@map("users")
}

model UserCustomMantra {
  id              String   @id
  userId          String   @map("user_id")
  name            String
  sanskrit        String
  transliteration String?
  meaning         String?
  segments        String   @default("[]")
  targetCount     Int      @default(108) @map("target_count")
  countingMode    String   @default("segments") @map("counting_mode")
  artworkKey      String?  @default("lotus") @map("artwork_key")
  imageUrl        String?  @map("image_url")
  currentCount    Int      @default(0) @map("current_count")
  completedRounds Int      @default(0) @map("completed_rounds")
  createdAt       DateTime @default(now()) @map("created_at")
  updatedAt       DateTime @default(now()) @updatedAt @map("updated_at")

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId], map: "idx_custom_mantras_user")
  @@map("user_custom_mantras")
}

model MalaRecord {
  id             String   @id
  userId         String   @map("user_id")
  mantraId       String   @map("mantra_id")
  completedMalas Int      @default(1) @map("completed_malas")
  recordedDate   String   @map("recorded_date")
  createdAt      DateTime @default(now()) @map("created_at")

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId], map: "idx_mala_records_user")
  @@index([mantraId], map: "idx_mala_records_mantra")
  @@index([recordedDate], map: "idx_mala_records_date")
  @@map("mala_records")
}

model Mantra {
  id              String   @id @default(uuid())
  slug            String   @unique
  name            String
  nameHi          String?
  deity           String?
  deityTitle      String?
  deityTitleHi    String?
  sanskrit        String
  transliteration String?
  translation     String?
  meaning         String?
  hindiMeaning    String?
  sanskritMeaning String?
  segments        String   @default("[]")
  targetCount     Int      @default(108)
  countingMode    String   @default("segments")
  artworkKey      String?  @default("lotus")
  imageUrl        String?  @map("image_url")
  orderIndex      Int      @default(0)
  isActive        Boolean  @default(true)
  createdAt       DateTime @default(now()) @map("created_at")

  @@map("mantras")
}

model Superadmin {
  id           String   @id @default(uuid())
  username     String   @unique
  email        String?  @unique
  passwordHash String   @map("password_hash")
  role         String   @default("superadmin")
  createdAt    DateTime @default(now()) @map("created_at")
  updatedAt    DateTime @updatedAt @map("updated_at")

  @@map("superadmins")
}