// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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

model Category {
  id          String    @id @default(cuid())
  name        String    @unique
  slug        String    @unique
  description String?
  icon        String?
  color       String?
  order       Int       @default(0)
  products    Product[]
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt
}

model Product {
  id               String    @id @default(cuid())
  name             String
  code             String    @unique
  slug             String    @unique
  description      String?
  benefits         String?
  ingredients      String?
  volume           String?
  fragrance        String?
  activeIngredient String?
  price            Float
  promotionalPrice Float?
  discountPercent  Int?
  page             Int
  image            String?
  images           String?
  isLaunch         Boolean   @default(false)
  isBestseller     Boolean   @default(false)
  isLowerPriceYear Boolean   @default(false)
  isKit            Boolean   @default(false)
  isCombo          Boolean   @default(false)
  rating           Float     @default(4.5)
  reviewCount      Int       @default(0)
  categoryId       String
  category         Category  @relation(fields: [categoryId], references: [id])
  createdAt        DateTime  @default(now())
  updatedAt        DateTime  @updatedAt

  @@index([categoryId])
  @@index([code])
  @@index([isLaunch])
  @@index([isLowerPriceYear])
}

model Kit {
  id               String    @id @default(cuid())
  name             String
  code             String    @unique
  description      String?
  price            Float
  promotionalPrice Float?
  discountPercent  Int?
  page             Int
  image            String?
  savings          String?
  createdAt        DateTime  @default(now())
  updatedAt        DateTime  @updatedAt
}

model CatalogPage {
  id        String   @id @default(cuid())
  pageNumber Int     @unique
  image     String
  thumbnail String?
  createdAt DateTime @default(now())
}

model Favorite {
  id        String   @id @default(cuid())
  productCode String
  sessionId String
  createdAt DateTime @default(now())

  @@unique([productCode, sessionId])
}

model ImportLog {
  id        String   @id @default(cuid())
  fileName  String
  status    String
  productsFound Int  @default(0)
  message   String?
  createdAt DateTime @default(now())
}

// Shared pin positions on catalog pages — persisted so every visitor sees
// the same dragged positions. Keyed by (page, code) so a product can have
// different positions on different pages.
model PinPosition {
  id        String   @id @default(cuid())
  page      Int
  code      String
  x         Float
  y         Float
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@unique([page, code])
  @@index([page])
}

// Manually-added pins (user clicked "+" and entered a product code).
// Shared so an admin's manual pins appear for every visitor.
model ManualPin {
  id        String   @id @default(cuid())
  page      Int
  code      String
  createdAt DateTime @default(now())

  @@unique([page, code])
  @@index([page])
}

// Auto-pins the admin has hidden (via the × button in manage-pins mode).
// Shared so a hidden pin stays hidden for every visitor — "when I remove a
// pin, it stays saved" across devices and sessions. Keyed by product code
// (a hidden pin is hidden on every page that product appears on).
model HiddenPin {
  id        String   @id @default(cuid())
  code      String   @unique
  createdAt DateTime @default(now())
}

// Distribuidores que cadastram nome + WhatsApp para gerar um link personalizado
// do catálogo. O `slug` (curto) vai na URL (?d=slug) que o distribuidor
// compartilha com seus clientes. Quando o cliente abre o link, o catálogo
// carrega vinculado a esse distribuidor e o checkout vai direto para o
// WhatsApp dele (wa.me/{whatsapp}?text=...).
model Distributor {
  id        String   @id @default(cuid())
  slug      String   @unique
  name      String
  whatsapp  String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([slug])
}
