// ------------------------------------------------------
// PRISMA CONFIGURATION
// ------------------------------------------------------

generator client {
  provider = "prisma-client"
  output   = "../app/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

// ------------------------------------------------------
// ENUMS
// ------------------------------------------------------

enum RoleEnum {
  Admin
  Support
}

enum ServiceType {
  HOURLY
  TRANSFER
  FROM_AIRPORT
  TO_AIRPORT
}

enum ReservationStatus {
  PENDING
  CONFIRMED
  CANCELLED
  COMPLETED
}

enum MessageStatus {
  NEW
  IN_PROGRESS
  RESPONDED
  ARCHIVED
}

enum GallerySection {
  HERO
  ABOUT_US
  ABOUT_BANNER
  SERVICES_BANNER
  FLEET_BANNER
  BOOK_BANNER
  CONTACT_BANNER
  SAFETY_SERVICE
  LUXURY_FLEET
}

enum GalleryPriority {
  LOW
  MEDIUM
  HIGH
  CRITICAL
}

enum SocialPlatform {
  FACEBOOK
  INSTAGRAM
  TWITTER
  LINKEDIN
  YOUTUBE
  TIKTOK
  WHATSAPP
}

// ------------------------------------------------------
// CMS & SITE CONTENT
// ------------------------------------------------------

model SiteSettings {
  id        String   @id @default("singleton")
  key       String   @unique // e.g., "landing-page-content"
  content   Json // Stores Hero, About Us, and Service Promise from your JSON
  updatedAt DateTime @updatedAt
}

// ------------------------------------------------------
// ADMIN & SECURITY (LOG TRACKING)
// ------------------------------------------------------

model AdminAccount {
  id           String         @id @default(cuid())
  email        String         @unique
  password     String // Hashed
  phone        String?
  profileImage String? // NEW
  fullName     String
  lastLogin    DateTime?
  role         RoleEnum       @default(Support)
  isActive     Boolean        @default(true)
  sessions     AdminSession[]
  auditLogs    AuditLog[] // Track activity
  createdAt    DateTime       @default(now())
  updatedAt    DateTime       @updatedAt
}

model AdminSession {
  id        String   @id @default(cuid())
  adminId   String
  token     String   @unique
  ipAddress String?
  userAgent String?
  expiresAt DateTime
  createdAt DateTime @default(now())

  admin AdminAccount @relation(fields: [adminId], references: [id], onDelete: Cascade)
}

model AuditLog {
  id        String   @id @default(cuid())
  adminId   String? // Nullable for system-level events
  action    String // e.g., "CREATE_RESERVATION", "UPDATE_CMS"
  entity    String // e.g., "SiteSettings", "Vehicle"
  entityId  String?
  oldValue  Json? // Snapshot before change
  newValue  Json? // Snapshot after change
  ipAddress String?
  createdAt DateTime @default(now())

  admin AdminAccount? @relation(fields: [adminId], references: [id], onDelete: SetNull)
}

// ------------------------------------------------------
// BUSINESS MODELS (SERVICES & FLEET)
// ------------------------------------------------------

model Service {
  id           String        @id @default(cuid())
  slug         String        @unique // e.g., "airport-transfers"
  title        String
  description  String        @db.Text
  image        String?
  isActive     Boolean       @default(true) // Whether the vehicle is active/available
  reservations Reservation[]
  createdAt    DateTime      @default(now())
  updatedAt    DateTime      @updatedAt
}

model Vehicle {
  id              String        @id @default(cuid())
  slug            String        @unique // e.g., "sprinter-van"
  name            String
  passengerMin    Int           @default(1)
  passengerMax    Int
  luggageCapacity Int
  baseRate        Decimal?
  imageUrl        String? // URL to vehicle image
  isActive        Boolean       @default(true) // Whether the vehicle is active/available
  reservations    Reservation[]
  createdAt       DateTime      @default(now())
  updatedAt       DateTime      @updatedAt
}

// ------------------------------------------------------
// USER SUBMISSIONS (RESERVATIONS & CONTACT)
// ------------------------------------------------------

model Reservation {
  id     String            @id @default(cuid())
  status ReservationStatus @default(PENDING)

  // Trip Details
  serviceId      String
  vehicleId      String?
  serviceType    ServiceType
  pickupDate     DateTime
  pickupTime     String
  passengers     Int
  luggage        Int
  pickupAddress  String
  dropoffAddress String

  // Customer Info
  firstName       String
  lastName        String
  phone           String
  email           String
  specialRequests String? @db.Text

  // Payment/Security (Note: Don't store CVV/Full CC in DB)
  cardHolder     String?
  lastFourDigits String?
  termsAccepted  Boolean

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  service Service  @relation(fields: [serviceId], references: [id])
  vehicle Vehicle? @relation(fields: [vehicleId], references: [id])
}

model ContactMessage {
  id        String        @id @default(cuid())
  name      String
  email     String
  phone     String?
  message   String        @db.Text
  isRead    Boolean       @default(false)
  status    MessageStatus @default(NEW)
  notes     String?       @db.Text // Internal admin notes
  createdAt DateTime      @default(now())
  updatedAt DateTime      @updatedAt
}

model ContactInfo {
  id        String         @id @default(cuid())
  phone     String?
  email     String?
  location  String?
  section   GallerySection
  isActive  Boolean        @default(true)
  createdAt DateTime       @default(now())
  updatedAt DateTime       @updatedAt
}

model TrustedClient {
  id        String   @id @default(cuid())
  name      String
  logo      String
  link      String?
  isActive  Boolean  @default(true)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model SocialMedia {
  id        String         @id @default(cuid())
  platform  SocialPlatform
  url       String
  isActive  Boolean        @default(true)
  createdAt DateTime       @default(now())
  updatedAt DateTime       @updatedAt

  @@unique([platform]) // prevents duplicate same platform
}

model GalleryImage {
  id        String          @id @default(cuid())
  isActive  Boolean         @default(true)
  section   GallerySection  @default(ABOUT_US)
  priority  GalleryPriority @default(LOW)
  image     String
  createdAt DateTime        @default(now())
  updatedAt DateTime        @updatedAt
}
