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

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

model Document {
  id           Int            @id @default(autoincrement())
  title        String
  s3Key        String
  status       String
  createdAt    DateTime       @default(now())
  updatedAt    DateTime       @updatedAt
  uploadedById Int
  uploadedBy   User           @relation("UploadedDocuments", fields: [uploadedById], references: [id])
  Notification Notification[]
  sharedWith   User[]         @relation("SharedDocuments")
}

model User {
  id                Int            @id @default(autoincrement())
  email             String         @unique
  name              String?
  password          String
  isAdmin           Boolean        @default(false)
  uploadedDocuments Document[]     @relation("UploadedDocuments")
  Notification      Notification[]
  sharedDocuments   Document[]     @relation("SharedDocuments")
  passwordResets    PasswordReset[]
  createdAt         DateTime       @default(now())
  updatedAt         DateTime       @updatedAt
}

model Notification {
  id         Int      @id @default(autoincrement())
  message    String
  read       Boolean  @default(false)
  userId     Int
  createdAt  DateTime @default(now())
  documentId Int
  document   Document @relation(fields: [documentId], references: [id])
  user       User     @relation(fields: [userId], references: [id])
}

model PasswordReset {
  id        Int      @id @default(autoincrement())
  token     String   @unique
  userId    Int
  user      User     @relation(fields: [userId], references: [id])
  expiresAt DateTime
  used      Boolean  @default(false)
  createdAt DateTime @default(now())
}
