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

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

// User & Role Management
model User {
  id           String        @id @default(cuid())
  name         String
  email        String        @unique
  passwordHash String
  role         String        @default("ADMIN") // SUPER_ADMIN, ADMIN, EDITOR
  phone        String?
  avatar       String?
  isActive     Boolean       @default(true)
  createdAt    DateTime      @default(now())
  updatedAt    DateTime      @updatedAt
  activityLogs ActivityLog[]
}

model ActivityLog {
  id        String   @id @default(cuid())
  userId    String?
  user      User?    @relation(fields: [userId], references: [id], onDelete: SetNull)
  action    String
  entity    String
  entityId  String?
  details   String?
  ipAddress String?
  userAgent String?
  createdAt DateTime @default(now())
}

// Product Catalog Models
model ProductCategory {
  id              String    @id @default(cuid())
  name            String
  slug            String    @unique
  description     String?
  image           String?
  icon            String?
  sortOrder       Int       @default(0)
  isActive        Boolean   @default(true)
  isFeatured      Boolean   @default(false)
  seoTitle        String?
  metaDescription String?
  createdAt       DateTime  @default(now())
  updatedAt       DateTime  @updatedAt
  products        Product[]
}

model Product {
  id               String          @id @default(cuid())
  name             String
  slug             String          @unique
  sku              String?         @unique
  price            String? // Price or starting price (e.g. "Rs. 35,000", "Contact for Price")
  categoryId       String
  category         ProductCategory @relation(fields: [categoryId], references: [id], onDelete: Cascade)
  subcategory      String?
  shortDescription String?
  fullDescription  String?
  features         String? // JSON string or newline list
  specifications   String? // JSON key-value pairs
  materials        String?
  dimensions       String?
  ageGroup         String?
  userCapacity     String?
  safetyInfo       String?
  warranty         String?
  installationInfo String?
  mainImage        String?
  pdfDatasheet     String?
  isFeatured       Boolean         @default(false)
  isActive         Boolean         @default(true)
  sortOrder        Int             @default(0)
  seoTitle         String?
  metaDescription  String?
  ogImage          String?
  createdAt        DateTime        @default(now())
  updatedAt        DateTime        @updatedAt
  images           ProductImage[]
  videos           ProductVideo[]
}

model ProductImage {
  id        String   @id @default(cuid())
  productId String
  product   Product  @relation(fields: [productId], references: [id], onDelete: Cascade)
  url       String
  altText   String?
  isMain    Boolean  @default(false)
  sortOrder Int      @default(0)
  createdAt DateTime @default(now())
}

model ProductVideo {
  id        String   @id @default(cuid())
  productId String
  product   Product  @relation(fields: [productId], references: [id], onDelete: Cascade)
  url       String
  videoType String   @default("UPLOAD") // UPLOAD, YOUTUBE, VIMEO
  posterUrl String?
  title     String?
  sortOrder Int      @default(0)
  createdAt DateTime @default(now())
}

// Services
model Service {
  id               String           @id @default(cuid())
  title            String
  slug             String           @unique
  shortDescription String?
  fullDescription  String?
  icon             String?
  image            String?
  sortOrder        Int              @default(0)
  isFeatured       Boolean          @default(false)
  isActive         Boolean          @default(true)
  seoTitle         String?
  metaDescription  String?
  createdAt        DateTime         @default(now())
  updatedAt        DateTime         @updatedAt
  features         ServiceFeature[]
}

model ServiceFeature {
  id          String   @id @default(cuid())
  serviceId   String
  service     Service  @relation(fields: [serviceId], references: [id], onDelete: Cascade)
  title       String
  description String?
  sortOrder   Int      @default(0)
  createdAt   DateTime @default(now())
}

// Projects & Showcases
model Project {
  id               String         @id @default(cuid())
  title            String
  slug             String         @unique
  category         String
  location         String
  clientName       String?
  completionDate   String?
  shortDescription String?
  fullDescription  String?
  specifications   String? // JSON string
  coverImage       String?
  videoUrl         String?
  videoThumbnail   String?
  isFeatured       Boolean        @default(false)
  isPublished      Boolean        @default(true)
  sortOrder        Int            @default(0)
  seoTitle         String?
  metaDescription  String?
  createdAt        DateTime       @default(now())
  updatedAt        DateTime       @updatedAt
  media            ProjectMedia[]
}

model ProjectMedia {
  id        String   @id @default(cuid())
  projectId String
  project   Project  @relation(fields: [projectId], references: [id], onDelete: Cascade)
  mediaType String   @default("IMAGE") // IMAGE, VIDEO
  url       String
  thumbnail String?
  title     String?
  caption   String?
  sortOrder Int      @default(0)
  createdAt DateTime @default(now())
}

// Portfolio
model PortfolioCategory {
  id        String          @id @default(cuid())
  name      String
  slug      String          @unique
  sortOrder Int             @default(0)
  createdAt DateTime        @default(now())
  items     PortfolioItem[]
}

model PortfolioItem {
  id             String             @id @default(cuid())
  title          String
  slug           String             @unique
  categoryId     String?
  category       PortfolioCategory? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
  mediaType      String             @default("IMAGE") // IMAGE, VIDEO
  url            String
  thumbnail      String?
  description    String?
  client         String?
  completionDate String?
  isFeatured     Boolean            @default(false)
  isPublished    Boolean            @default(true)
  sortOrder      Int                @default(0)
  createdAt      DateTime           @default(now())
  updatedAt      DateTime           @updatedAt
}

// Catalogs
model Catalog {
  id            String   @id @default(cuid())
  title         String
  slug          String   @unique
  edition       String?
  year          String?
  description   String?
  coverImage    String?
  pdfUrl        String
  fileSize      String?
  downloadCount Int      @default(0)
  isFeatured    Boolean  @default(false)
  isPublished   Boolean  @default(true)
  sortOrder     Int      @default(0)
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt
}

// Blog Posts & SEO Content
model BlogCategory {
  id          String     @id @default(cuid())
  name        String
  slug        String     @unique
  description String?
  createdAt   DateTime   @default(now())
  posts       BlogPost[]
}

model BlogPost {
  id              String        @id @default(cuid())
  title           String
  slug            String        @unique
  excerpt         String?
  content         String
  featuredImage   String?
  author          String        @default("Forever Fiber Glass Team")
  categoryId      String?
  category        BlogCategory? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
  tags            String? // Comma-separated or JSON list
  readTime        String?       @default("4 min read")
  isPublished     Boolean       @default(true)
  isFeatured      Boolean       @default(false)
  viewsCount      Int           @default(0)
  seoTitle        String?
  metaDescription String?
  canonicalUrl    String?
  ogImage         String?
  publishedAt     DateTime      @default(now())
  createdAt       DateTime      @default(now())
  updatedAt       DateTime      @updatedAt
}

// Testimonials & Social Proof
model Testimonial {
  id           String   @id @default(cuid())
  customerName String
  organization String?
  designation  String?
  photo        String?
  review       String
  rating       Int      @default(5)
  isFeatured   Boolean  @default(true)
  isPublished  Boolean  @default(true)
  sortOrder    Int      @default(0)
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
}

model ClientLogo {
  id         String   @id @default(cuid())
  name       String
  logoUrl    String
  websiteUrl String?
  clientType String? // School, Municipality, Resort, Housing, Gym
  sortOrder  Int      @default(0)
  isActive   Boolean  @default(true)
  createdAt  DateTime @default(now())
}

model FAQ {
  id          String   @id @default(cuid())
  question    String
  answer      String
  category    String?  @default("General")
  sortOrder   Int      @default(0)
  isPublished Boolean  @default(true)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

// Hero Slide Configuration
model HeroSlide {
  id                  String   @id @default(cuid())
  badgeText           String?  @default("Proudly Made in Nepal")
  title               String
  highlightedTitle    String?
  subtitle            String?
  primaryButtonText   String?  @default("Explore Products")
  primaryButtonLink   String?  @default("/products")
  secondaryButtonText String?  @default("Get in Touch")
  secondaryButtonLink String?  @default("/contact")
  imageUrl            String?
  videoUrl            String?
  sortOrder           Int      @default(0)
  isActive            Boolean  @default(true)
  createdAt           DateTime @default(now())
  updatedAt           DateTime @updatedAt
}

// Leads & Form Submissions
model ContactSubmission {
  id                     String   @id @default(cuid())
  fullName               String
  organization           String?
  email                  String
  phone                  String
  subject                String?
  message                String
  preferredContactMethod String?  @default("Phone")
  consentGiven           Boolean  @default(true)
  status                 String   @default("NEW") // NEW, CONTACTED, IN_PROGRESS, CLOSED, SPAM
  adminNotes             String?
  ipAddress              String?
  createdAt              DateTime @default(now())
  updatedAt              DateTime @updatedAt
}

model QuoteRequest {
  id                     String             @id @default(cuid())
  quoteNumber            String             @unique
  fullName               String
  organization           String?
  email                  String
  phone                  String
  province               String?
  district               String?
  city                   String?
  projectLocation        String?
  customerType           String? // School, Municipality, Resort, Gym, Private, Contractor
  productCategory        String?
  estimatedQuantity      String?
  projectDescription     String?
  expectedCompletionDate String?
  estimatedBudget        String?
  preferredContactMethod String?            @default("Phone")
  consentGiven           Boolean            @default(true)
  status                 String             @default("NEW") // NEW, REVIEWING, CONTACTED, QUOTED, WON, LOST, SPAM
  adminNotes             String?
  followUpDate           DateTime?
  createdAt              DateTime           @default(now())
  updatedAt              DateTime           @updatedAt
  items                  QuoteRequestItem[]
  attachments            QuoteAttachment[]
}

model QuoteRequestItem {
  id             String       @id @default(cuid())
  quoteRequestId String
  quoteRequest   QuoteRequest @relation(fields: [quoteRequestId], references: [id], onDelete: Cascade)
  productId      String?
  productName    String
  categoryName   String?
  quantity       Int          @default(1)
  notes          String?
}

model QuoteAttachment {
  id             String       @id @default(cuid())
  quoteRequestId String
  quoteRequest   QuoteRequest @relation(fields: [quoteRequestId], references: [id], onDelete: Cascade)
  fileUrl        String
  fileName       String
  fileSize       String?
  mimeType       String?
  createdAt      DateTime     @default(now())
}

model NewsletterSubscriber {
  id           String   @id @default(cuid())
  email        String   @unique
  isActive     Boolean  @default(true)
  subscribedAt DateTime @default(now())
}

// Site Settings & Branches
model SiteSetting {
  id                     String   @id @default(cuid())
  companyName            String   @default("Forever Fiber Glass and Gym")
  tagline                String   @default("Built for Fun, Made to Last")
  country                String   @default("Nepal")
  primaryLocation        String   @default("Kirtipur, Nepal 44618")
  branchLocation         String   @default("Dhangadhi, Kailali")
  primaryEmail           String   @default("foreverfiberglass15@gmail.com")
  secondaryEmail         String?
  primaryPhone           String   @default("984-0840363")
  secondaryPhone         String   @default("985-1415365")
  whatsappPhone          String   @default("984-0840363")
  businessHours          String   @default("Sun - Fri: 8:00 AM - 6:00 PM")
  googleMapsEmbed        String?
  googleBusinessUrl      String?
  facebookUrl            String?  @default("https://facebook.com/foreverfiberglass")
  instagramUrl           String?
  linkedinUrl            String?
  youtubeUrl             String?
  defaultSeoTitle        String   @default("Forever Fiber Glass & Gym | Outdoor Gym & Playground Manufacturer Nepal")
  defaultMetaDescription String   @default("Leading manufacturer of outdoor gym equipment, children playground equipment, fiberglass products, classroom furniture, and SS railings in Nepal.")
  globalOgImage          String?
  footerDescription      String   @default("Premier Nepali manufacturer of robust outdoor gym gear, park fitness machines, custom fiberglass fabrications, and commercial playground structures.")
  copyrightText          String   @default("Forever Fiber Glass and Gym. All Rights Reserved.")
  updatedAt              DateTime @updatedAt
}

model Branch {
  id           String   @id @default(cuid())
  name         String
  address      String
  phone        String
  email        String?
  isMain       Boolean  @default(false)
  googleMapUrl String?
  sortOrder    Int      @default(0)
  createdAt    DateTime @default(now())
}

model MediaFile {
  id           String   @id @default(cuid())
  originalName String
  fileName     String   @unique
  url          String
  mimeType     String
  size         Int
  width        Int?
  height       Int?
  category     String?  @default("general")
  createdAt    DateTime @default(now())
}

model Redirect {
  id         String   @id @default(cuid())
  fromPath   String   @unique
  toPath     String
  statusCode Int      @default(301)
  createdAt  DateTime @default(now())
}
