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

datasource db {
  provider = "postgresql"
}

enum Role {
  SUPER_ADMIN
  ADMIN
  SALES
  CONTENT_MANAGER
}

enum InventoryStatus {
  IN_STOCK
  LIMITED_STOCK
  OUT_OF_STOCK
  TEST_RIDE_ONLY
  COMING_SOON
}

enum BookingStatus {
  PENDING
  CONFIRMED
  COMPLETED
  CANCELLED
}

enum AssetStatus {
  PENDING
  UPLOADED
  NEEDS_OPTIMIZATION
  OPTIMIZED
  PUBLISHED
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  passwordHash  String?
  role          Role      @default(SALES)
  accounts      Account[]
  sessions      Session[]
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
}

model Account {
  id                String  @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String? @db.Text
  access_token      String? @db.Text
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String? @db.Text
  session_state     String?

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       String
  expires      DateTime

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

model Brand {
  id               String    @id
  name             String
  slug             String    @unique
  shortDescription String
  logoText         String
  keyStrength      String
  popularModels    String[]
  isFeatured       Boolean   @default(false)
  scooters         Scooter[]
  offers           Offer[]
  createdAt        DateTime  @default(now())
  updatedAt        DateTime  @updatedAt
}

model Scooter {
  id               String            @id
  slug             String            @unique
  brandId          String
  name             String
  shortDescription String
  longDescription  String            @db.Text
  price            Int
  offerPrice       Int
  rangeKm          Int
  topSpeedKmph     Int
  chargingTime     String
  battery          String
  motorPower       String
  warranty         String
  colors           String[]
  heroImage        String
  thumbnailImage   String
  posterImage      String
  arEnabled        Boolean           @default(false)
  isFeatured       Boolean           @default(false)
  published        Boolean           @default(true)
  specs            Json
  brand            Brand             @relation(fields: [brandId], references: [id], onDelete: Cascade)
  images           ScooterImage[]
  asset3d          ScooterAsset3D?
  inventory        Inventory[]
  offers           Offer[]
  galleryImages    GalleryImage[]
  bookings         TestRideBooking[]
  leads            Lead[]
  createdAt        DateTime          @default(now())
  updatedAt        DateTime          @updatedAt
}

model ScooterImage {
  id        String   @id @default(cuid())
  scooterId String
  url       String
  alt       String?
  sortOrder Int      @default(0)
  scooter   Scooter  @relation(fields: [scooterId], references: [id], onDelete: Cascade)
}

model ScooterAsset3D {
  id        String      @id @default(cuid())
  scooterId String      @unique
  glbUrl    String?
  usdzUrl   String?
  status    AssetStatus @default(PENDING)
  scooter   Scooter     @relation(fields: [scooterId], references: [id], onDelete: Cascade)
  createdAt DateTime    @default(now())
  updatedAt DateTime    @updatedAt
}

model Branch {
  id          String            @id
  name        String
  slug        String            @unique
  type        String
  city        String
  district    String
  phone       String
  whatsapp    String
  openingHours String
  mapLink     String
  branchImage String            @default("")
  inventory   Inventory[]
  offers      Offer[]
  galleryImages GalleryImage[]
  bookings    TestRideBooking[]
  leads       Lead[]
  createdAt   DateTime          @default(now())
  updatedAt   DateTime          @updatedAt
}

model Inventory {
  id                String          @id
  scooterId         String
  branchId          String
  status            InventoryStatus
  quantity          Int             @default(0)
  testRideAvailable Boolean         @default(false)
  scooter           Scooter         @relation(fields: [scooterId], references: [id], onDelete: Cascade)
  branch            Branch          @relation(fields: [branchId], references: [id], onDelete: Cascade)
  updatedAt         DateTime        @updatedAt

  @@unique([scooterId, branchId])
}

model Part {
  id            String   @id
  name          String
  category      String
  price         Int
  image         String
  compatibility String[]
  inquiryOnly   Boolean  @default(false)
  stockStatus   InventoryStatus @default(IN_STOCK)
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt
}

model Offer {
  id            String   @id
  category      String
  title         String
  description   String   @db.Text
  discountLabel String
  startsAt      DateTime?
  validUntil    DateTime
  active        Boolean  @default(true)
  brandId       String?
  scooterId     String?
  branchId      String?
  brand         Brand?   @relation(fields: [brandId], references: [id], onDelete: SetNull)
  scooter       Scooter? @relation(fields: [scooterId], references: [id], onDelete: SetNull)
  branch        Branch?  @relation(fields: [branchId], references: [id], onDelete: SetNull)
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt
}

model GalleryImage {
  id        String   @id
  category  String
  title     String
  image     String
  alt       String
  featured  Boolean  @default(false)
  branchId  String?
  scooterId String?
  branch    Branch?  @relation(fields: [branchId], references: [id], onDelete: SetNull)
  scooter   Scooter? @relation(fields: [scooterId], references: [id], onDelete: SetNull)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Testimonial {
  id           String   @id
  customerName String
  location     String
  rating       Int
  comment      String   @db.Text
  scooterName  String?
  image        String
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
}

model TestRideBooking {
  id          String        @id @default(cuid())
  fullName    String
  phone       String
  email       String?
  branchId    String?
  scooterId   String?
  preferredDate DateTime?
  preferredTime String?
  message     String?       @db.Text
  status      BookingStatus @default(PENDING)
  branch      Branch?       @relation(fields: [branchId], references: [id], onDelete: SetNull)
  scooter     Scooter?      @relation(fields: [scooterId], references: [id], onDelete: SetNull)
  createdAt   DateTime      @default(now())
  updatedAt   DateTime      @updatedAt
}

model Lead {
  id        String   @id @default(cuid())
  fullName  String
  phone     String
  email     String?
  subject   String?
  message   String?  @db.Text
  source    String?
  status    String   @default("NEW")
  notes     String?  @db.Text
  branchId  String?
  scooterId String?
  branch    Branch?  @relation(fields: [branchId], references: [id], onDelete: SetNull)
  scooter   Scooter? @relation(fields: [scooterId], references: [id], onDelete: SetNull)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Faq {
  id        String   @id
  question  String
  answer    String   @db.Text
  category  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model NewsPopup {
  id          String   @id @default(cuid())
  title       String
  description String   @db.Text
  imageUrl    String?
  ctaLabel    String?
  ctaUrl      String?
  isActive    Boolean  @default(true)
  startsAt    DateTime?
  endsAt      DateTime?
  showOnce    Boolean  @default(true)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

model HomepageBanner {
  id        String   @id @default(cuid())
  imageUrl  String
  altText   String
  ctaUrl    String?
  isActive  Boolean  @default(true)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model CmsSetting {
  id        String   @id @default(cuid())
  key       String   @unique
  value     Json
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
