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

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

model User {
  id           String    @id @default(uuid())
  email        String    @unique
  passwordHash String
  firstName    String
  lastName     String
  phone        String?
  avatarUrl    String?
  gender       String?
  dateOfBirth  String?
  role         String    @default("TRAVELER") // "TRAVELER", "GUIDE", "BUSINESS", "ADMIN"
  createdAt    DateTime  @default(now())
  updatedAt    DateTime  @updatedAt

  businessProfile BusinessProfile?
  bookings        Booking[]
  wishlists       Wishlist[]
  notifications   Notification[]
  tours           Tour[]           @relation("GuideTours")

  @@map("users")
}

model BusinessProfile {
  id                 String   @id @default(uuid())
  userId             String   @unique
  user               User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  businessName       String
  registrationNumber String   @unique
  foundingDate       String?
  fayidaId           String?
  aboutBusiness      String?
  phoneNumber        String?
  licenseImages      String   @default("[]") // JSON stringified array of image URLs
  status             String   @default("PENDING") // "PENDING", "VERIFIED", "REJECTED"
  createdAt          DateTime @default(now())
  updatedAt          DateTime @updatedAt

  @@map("business_profiles")
}

model Tour {
  id                 Int      @id @default(autoincrement())
  guideId            String
  guide              User     @relation("GuideTours", fields: [guideId], references: [id], onDelete: Cascade)
  tourName           String
  tourType           String   // "Hiking", "Nature", "Adventure", "Cultural"
  destination        String
  startingPoint      String
  overview           String
  highlights         String   @default("[]") // JSON array of string highlights
  photos             String   @default("[]") // JSON array of image URLs
  
  groupCapacity      Int      @default(10)
  bookedCount        Int      @default(0)
  startDate          String
  endDate            String
  
  price              Float    @default(0)
  discountPercent    Float?   @default(0)
  totalPrice         Float    @default(0)
  
  includes           String   @default("[]") // JSON array
  notIncludes        String   @default("[]") // JSON array
  essentialEquipment String   @default("[]") // JSON array
  activities         String   @default("{}") // JSON day-by-day itinerary
  
  rating             Float    @default(4.8)
  reviewCount        Int      @default(120)
  isPublished        Boolean  @default(true)
  createdAt          DateTime @default(now())
  updatedAt          DateTime @updatedAt

  bookings  Booking[]
  wishlists Wishlist[]

  @@index([tourType])
  @@index([destination])
  @@map("tours")
}

model Booking {
  id               String   @id @default(uuid())
  bookingReference String   @unique // e.g. WDT-2026-X8K912
  tourId           Int
  tour             Tour     @relation(fields: [tourId], references: [id], onDelete: Restrict)
  userId           String
  user             User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  
  passengerCount   Int      @default(1)
  totalAmount      Float
  status           String   @default("CONFIRMED") // "PENDING", "CONFIRMED", "COMPLETED", "CANCELLED"
  qrToken          String   @unique
  paymentProvider  String?  @default("telebirr") // "telebirr", "chapa", "cbe"
  
  createdAt        DateTime @default(now())
  updatedAt        DateTime @updatedAt

  passengers Passenger[]

  @@index([userId])
  @@index([tourId])
  @@map("bookings")
}

model Passenger {
  id        String   @id @default(uuid())
  bookingId String
  booking   Booking  @relation(fields: [bookingId], references: [id], onDelete: Cascade)
  fullName  String
  email     String?
  phone     String?
  createdAt DateTime @default(now())

  @@map("passengers")
}

model Wishlist {
  userId    String
  tourId    Int
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  tour      Tour     @relation(fields: [tourId], references: [id], onDelete: Cascade)
  createdAt DateTime @default(now())

  @@id([userId, tourId])
  @@map("wishlists")
}

model Notification {
  id        String   @id @default(uuid())
  userId    String
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  title     String
  message   String
  isRead    Boolean  @default(false)
  link      String?
  createdAt DateTime @default(now())

  @@map("notifications")
}
