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

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

model Post {
  id          String    @id @default(cuid())
  title       String    @db.VarChar(500)
  slug        String    @unique @db.VarChar(500)
  locale      String    @default("fa") @db.VarChar(5)
  category    String    @db.VarChar(100)
  excerpt     String?   @db.Text
  body        String?   @db.LongText
  coverImage  String?   @db.VarChar(1000)
  featured    Boolean   @default(false)
  publishedAt DateTime  @default(now())
  seoTitle    String?   @db.VarChar(255)
  seoDesc     String?   @db.VarChar(500)
  tags        PostTag[]
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt

  @@index([locale, featured])
  @@index([locale, category])
  @@index([publishedAt(sort: Desc)])
}

model Project {
  id          String   @id @default(cuid())
  title       String   @db.VarChar(500)
  slug        String   @unique @db.VarChar(500)
  locale      String   @default("fa") @db.VarChar(5)
  projectType String   @db.VarChar(100)
  description String?  @db.Text
  body        String?  @db.LongText
  coverImage  String?  @db.VarChar(1000)
  gallery     String?  @db.Text
  techStack   String?  @db.Text
  toolsUsed   String?  @db.Text
  liveUrl     String?  @db.VarChar(500)
  githubUrl   String?  @db.VarChar(500)
  featured    Boolean  @default(false)
  seoTitle    String?  @db.VarChar(255)
  seoDesc     String?  @db.VarChar(500)
  sortOrder   Int      @default(0)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  @@index([locale, projectType])
  @@index([locale, featured])
}

model Product {
  id          String   @id @default(cuid())
  title       String   @db.VarChar(500)
  slug        String   @unique @db.VarChar(500)
  locale      String   @default("fa") @db.VarChar(5)
  description String?  @db.Text
  price       Float?
  currency    String   @default("IRR") @db.VarChar(10)
  coverImage  String?  @db.VarChar(1000)
  purchaseUrl String?  @db.VarChar(500)
  productType String   @default("digital") @db.VarChar(50)
  featured    Boolean  @default(false)
  seoTitle    String?  @db.VarChar(255)
  seoDesc     String?  @db.VarChar(500)
  sortOrder   Int      @default(0)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  @@index([locale])
}

model Tag {
  id    String    @id @default(cuid())
  title String    @db.VarChar(100)
  slug  String    @unique @db.VarChar(100)
  posts PostTag[]
}

model PostTag {
  postId String
  tagId  String
  post   Post   @relation(fields: [postId], references: [id], onDelete: Cascade)
  tag    Tag    @relation(fields: [tagId], references: [id], onDelete: Cascade)

  @@id([postId, tagId])
}

model TimelineEvent {
  id          String   @id @default(cuid())
  title       String   @db.VarChar(500)
  date        DateTime
  description String?  @db.Text
  icon        String?  @db.VarChar(10)
  category    String   @default("career") @db.VarChar(50)
  sortOrder   Int      @default(0)
  createdAt   DateTime @default(now())

  @@index([date(sort: Desc)])
}

model UsesItem {
  id          String   @id @default(cuid())
  title       String   @db.VarChar(255)
  description String?  @db.Text
  category    String   @db.VarChar(50)
  url         String?  @db.VarChar(500)
  image       String?  @db.VarChar(1000)
  sortOrder   Int      @default(0)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  @@index([category])
}

model SiteSettings {
  id              String   @id @default("main")
  siteTitle       String   @default("Ali Taghavi") @db.VarChar(255)
  description     String?  @db.Text
  currentStatus   String?  @db.Text
  telegramChannel String?  @db.VarChar(255)
  socialGithub    String?  @db.VarChar(255)
  socialLinkedin  String?  @db.VarChar(255)
  socialTwitter   String?  @db.VarChar(255)
  socialTelegram  String?  @db.VarChar(255)
  socialInstagram String?  @db.VarChar(255)
  updatedAt       DateTime @updatedAt
}

model AdminUser {
  id        String   @id @default(cuid())
  username  String   @unique @db.VarChar(100)
  password  String   @db.VarChar(255)
  createdAt DateTime @default(now())
}

model ContactMessage {
  id        String   @id @default(cuid())
  name      String   @db.VarChar(255)
  email     String   @db.VarChar(255)
  subject   String?  @db.VarChar(500)
  message   String   @db.LongText
  isRead    Boolean  @default(false)
  createdAt DateTime @default(now())

  @@index([isRead])
  @@index([createdAt(sort: Desc)])
}
