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

datasource db {
  provider = "postgresql"
}

enum Role {
  USER
  ADMIN
  USER_MODERATOR
  LISTING_MODERATOR
}

enum UserStatus {
  PENDING
  ACTIVE
  DISABLED
  REJECTED
  REMOVED
}

enum ListingStatus {
  DRAFT
  PENDING
  PUBLISHED
  REJECTED
  REMOVED
}

model User {
  id                 String              @id @default(cuid())
  email              String              @unique
  passwordHash       String              @default("")
  name               String?
  phone              String?
  role               Role                @default(USER)
  status             UserStatus          @default(PENDING)
  emailVerifiedAt    DateTime?
  approvedAt         DateTime?
  rejectedAt         DateTime?
  rejectedReason     String?
  removedAt          DateTime?
  removedById        String?
  removedReason      String?
  listings           Listing[]
  approvedListings   Listing[]           @relation("ListingApprovedBy")
  verificationTokens VerificationToken[]
  createdAt          DateTime            @default(now())
  updatedAt          DateTime            @updatedAt
}

model Listing {
  id                     String              @id @default(cuid())
  ownerId                String
  owner                  User                @relation(fields: [ownerId], references: [id])
  status                 ListingStatus       @default(PENDING)
  approvedAt             DateTime?
  approvedById           String?
  approvedBy             User?               @relation("ListingApprovedBy", fields: [approvedById], references: [id])
  rejectedAt             DateTime?
  rejectedById           String?
  rejectedReason         String?
  removedAt              DateTime?
  removedById            String?
  removedReason          String?
  country                String?
  region                 String?
  city                   String?
  streetAddress          String?
  addressNote            String?
  latitude               Float?
  longitude              Float?
  maxGuests              Int?
  bedrooms               Int?
  beds                   Int?
  bathrooms              Int?
  hasSauna               Boolean             @default(false)
  hasFireplace           Boolean             @default(false)
  hasWifi                Boolean             @default(false)
  petsAllowed            Boolean             @default(false)
  byTheLake              Boolean             @default(false)
  hasAirConditioning     Boolean             @default(false)
  hasKitchen             Boolean             @default(false)
  hasDishwasher          Boolean             @default(false)
  hasWashingMachine      Boolean             @default(false)
  hasBarbecue            Boolean             @default(false)
  hasMicrowave           Boolean             @default(false)
  hasFreeParking         Boolean             @default(false)
  hasSkiPass             Boolean             @default(false)
  evChargingAvailable    Boolean             @default(false)
  evChargingOnSite       Boolean             @default(false)
  wheelchairAccessible   Boolean             @default(false)
  calendarUrls           String[]            @db.Text @default([])
  priceWeekdayEuros      Int?
  priceWeekendEuros      Int?
  contactName            String?
  contactEmail           String?
  contactPhone           String?
  externalUrl            String?
  published              Boolean             @default(true)
  isSample               Boolean             @default(false)
  translations           ListingTranslation[]
  images                 ListingImage[]
  createdAt              DateTime            @default(now())
  updatedAt              DateTime            @updatedAt
}

model ListingTranslation {
  id          String   @id @default(cuid())
  listingId   String
  listing     Listing  @relation(fields: [listingId], references: [id])
  locale      String
  title       String
  slug        String
  description String
  teaser      String?
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  @@unique([listingId, locale])
  @@unique([slug, locale])
}

model ListingImage {
  id        String   @id @default(cuid())
  listingId String
  listing   Listing  @relation(fields: [listingId], references: [id])
  url       String?
  data      Bytes?
  mimeType  String?
  size      Int?
  altText   String?
  isCover   Boolean  @default(false)
  order     Int      @default(0)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model SiteSettings {
  id                               String   @id @default("default")
  requireLoginForContactDetails    Boolean  @default(true)
  createdAt                        DateTime @default(now())
  updatedAt                        DateTime @updatedAt
}

model VerificationToken {
  id         String   @id @default(cuid())
  userId     String
  user       User     @relation(fields: [userId], references: [id])
  token      String   @unique
  type       String
  expiresAt  DateTime
  consumedAt DateTime?
  createdAt  DateTime @default(now())

  @@index([userId])
}
