generator client {
  provider      = "prisma-client-js"
  output        = "../node_modules/.prisma/client"
  binaryTargets = ["linux-musl-openssl-3.0.x", "native"]
}

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

model Note {
  id                 String              @id @default(cuid())
  title              String?
  content            String
  color              String              @default("default")
  isPinned           Boolean             @default(false)
  isArchived         Boolean             @default(false)
  type               String              @default("text")
  checkItems         String?
  labels             String?
  images             String?
  links              String?
  reminder           DateTime?
  isReminderDone     Boolean             @default(false)
  reminderRecurrence String?
  reminderLocation   String?
  isMarkdown         Boolean             @default(false)
  size               String              @default("small")
  embedding          String?
  sharedWith         String?
  userId             String?
  order              Int                 @default(0)
  notebookId         String?
  createdAt          DateTime            @default(now())
  updatedAt          DateTime            @updatedAt
  autoGenerated      Boolean?
  aiProvider         String?
  aiConfidence       Int?
  language           String?
  languageConfidence Float?
  lastAiAnalysis     DateTime?
}

model Notebook {
  id        String   @id @default(cuid())
  name      String
  icon      String?
  color     String?
  order     Int
  userId    String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Label {
  id         String    @id @default(cuid())
  name       String
  color      String    @default("gray")
  notebookId String?
  userId     String?
  createdAt  DateTime  @default(now())
  updatedAt  DateTime  @updatedAt
}

model User {
  id                 String              @id @default(cuid())
  name               String?
  email              String              @unique
  emailVerified      DateTime?
  password           String?
  role               String              @default("USER")
  image              String?
  theme              String              @default("light")
  resetToken         String?             @unique
  resetTokenExpiry   DateTime?
  createdAt          DateTime            @default(now())
  updatedAt          DateTime            @updatedAt
}

model Account {
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?
  access_token      String?
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?
  session_state     String?
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt

  @@id([provider, providerAccountId])
}

model Session {
  sessionToken String   @unique
  userId       String
  expires      DateTime
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
}

model VerificationToken {
  identifier String
  token      String
  expires    DateTime

  @@id([identifier, token])
}

model NoteShare {
  id          String    @id @default(cuid())
  noteId      String
  userId      String
  sharedBy    String
  status      String    @default("pending")
  permission  String    @default("view")
  notifiedAt  DateTime?
  respondedAt DateTime?
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt

  @@unique([noteId, userId])
}

model SystemConfig {
  key   String @id
  value String
}

model AiFeedback {
  id               String   @id @default(cuid())
  noteId           String
  userId           String?
  feedbackType     String
  feature          String
  originalContent  String
  correctedContent String?
  metadata         String?
  createdAt        DateTime  @default(now())
}

model MemoryEchoInsight {
  id              String   @id @default(cuid())
  userId          String?
  note1Id         String
  note2Id         String
  similarityScore Float
  insight         String
  insightDate     DateTime @default(now())
  viewed          Boolean  @default(false)
  feedback        String?
  dismissed       Boolean  @default(false)

  @@unique([userId, insightDate])
}

model UserAISettings {
  userId                 String  @id
  titleSuggestions       Boolean @default(true)
  semanticSearch         Boolean @default(true)
  paragraphRefactor      Boolean @default(true)
  memoryEcho             Boolean @default(true)
  memoryEchoFrequency    String  @default("daily")
  aiProvider             String  @default("auto")
  preferredLanguage      String  @default("auto")
  fontSize               String  @default("medium")
  demoMode               Boolean @default(false)
  showRecentNotes        Boolean @default(false)
  emailNotifications      Boolean @default(false)
  desktopNotifications   Boolean @default(false)
  anonymousAnalytics      Boolean @default(false)
}
