// prisma/schema.prisma

generator client {
  provider     = "prisma-client"
  moduleFormat = "cjs"
  output       = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}

model Post {
  id                 Int      @id @default(autoincrement())
  title              String
  prompt             String
  content            String   @db.Text
  imageUrl           String?
  style              String   @default("general")
  tone               String?   @default("")
  isFbPostState      Int      @default(0)
  isTwitterPostState Int      @default(0)
  isTiktokPostState  Int      @default(0)
  draft              String?  @db.Text
  tokensUsed         Int     @default(0)
  model              String?
  reviewNotes        String?
  status             String   @default("pending") // Các trạng thái: pending, approved, published, rejected
  createdAt          DateTime @default(now())
  updatedAt          DateTime @updatedAt
}

model Config {
  id    Int    @id @default(autoincrement())
  key   String @unique
  value String
}

model Trend {
  id            Int    @id @default(autoincrement())
  title         String
  description   String? @db.Text
  url           String?
  score         Int  @default(0)
  source           String @db.Text
  category           String?
  geo                 String? @db.VarChar()
  tags                Json?
  engagement          Json?
  raw                 Json?
  fingerprint         String? @db.VarChar()
  sourceTimestamp     DateTime?
  createdAt           DateTime @default(now())
  updatedAt           DateTime? @default(now())

  @@index([score]) // Tạo index cho cột name
  @@index([category]) // Tạo index cho cột name
  @@index([geo]) // Tạo index cho cột name
  @@index([sourceTimestamp]) // Tạo index cho cột name

}
