// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

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

model User {
  id            Int      @id @default(autoincrement())
  email         String   @unique
  password      String
  roles         Json     @default("[\"ROLE_USER\"]")
  authenticated Boolean  @default(true)
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt

  // Relations
  config      KomgaConfig?
  preferences Preferences?
  favorites   Favorite[]

  @@map("users")
}

model KomgaConfig {
  id         Int      @id @default(autoincrement())
  userId     Int      @unique
  url        String
  username   String
  authHeader String
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

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

  @@map("komgaconfigs")
}

model Preferences {
  id                  Int      @id @default(autoincrement())
  userId              Int      @unique
  showThumbnails      Boolean  @default(true)
  showOnlyUnread      Boolean  @default(false)
  displayMode         Json
  background          Json
  readerPrefetchCount Int      @default(5)
  createdAt           DateTime @default(now())
  updatedAt           DateTime @updatedAt

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

  @@map("preferences")
}

model Favorite {
  id        Int      @id @default(autoincrement())
  userId    Int
  seriesId  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

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

  @@unique([userId, seriesId])
  @@index([userId])
  @@map("favorites")
}
