generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"] // cPanel (RHEL) deploy için
}

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

model Product {
  id         Int         @id @default(autoincrement())
  slug       String      @unique
  nameTr     String
  nameEn     String
  descTr     String?     @db.Text
  descEn     String?     @db.Text
  category   String      // "CUBO" | "RECTA" | "GLOBE" | "OTHER"
  size       String?
  priceSelf  Float       // Kurumsal site görüntüleme fiyatı
  priceB2B   Float       // Bayi fiyatı (USD)
  stock      Int         @default(0)
  images     String      @db.Text // JSON array of image paths
  isActive   Boolean     @default(true)
  createdAt  DateTime    @default(now())
  updatedAt  DateTime    @updatedAt
  orderItems OrderItem[]
}

model Dealer {
  id           Int      @id @default(autoincrement())
  dealerCode   String   @unique
  password     String
  companyName  String
  contactName  String
  email        String   @unique
  phone        String?
  address      String?  @db.Text
  city         String?
  discountRate Float    @default(0)
  isAdmin      Boolean  @default(false)
  isActive     Boolean  @default(true)
  createdAt    DateTime @default(now())
  orders       Order[]
}

model Order {
  id              Int           @id @default(autoincrement())
  orderNo         String        @unique
  dealer          Dealer        @relation(fields: [dealerId], references: [id])
  dealerId        Int
  status          OrderStatus   @default(PENDING)
  paymentMethod   PaymentMethod
  paymentStatus   PaymentStatus @default(WAITING)
  totalUSD        Float
  notes           String?       @db.Text
  shippingAddress String        @db.Text
  iyzicoToken     String?       @unique
  conversationId  String?
  items           OrderItem[]
  createdAt       DateTime      @default(now())
  updatedAt       DateTime      @updatedAt
}

model OrderItem {
  id        Int     @id @default(autoincrement())
  order     Order   @relation(fields: [orderId], references: [id])
  orderId   Int
  product   Product @relation(fields: [productId], references: [id])
  productId Int
  quantity  Int
  unitPrice Float
}

enum OrderStatus {
  PENDING
  CONFIRMED
  PREPARING
  SHIPPED
  DELIVERED
  CANCELLED
}

enum PaymentMethod {
  ONLINE
  BANK_TRANSFER
}

enum PaymentStatus {
  WAITING
  PAID
  FAILED
}

model Blog {
  id          Int      @id @default(autoincrement())
  slug        String   @unique
  titleTr     String
  titleEn     String?
  excerpt     String?  @db.Text
  contentTr   String   @db.LongText
  contentEn   String?  @db.LongText
  coverImage  String?
  isPublished Boolean  @default(false)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}
