generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}

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

enum UserRole {
  admin
  volunteer
  donor
  public
}

enum BurrowStatus {
  active
  inactive
  destroyed
}

enum DonationCampaign {
  land_preservation
  volunteer_equipment
  general
}

enum EventType {
  cleanup
  educational
  fundraiser
}

enum StreamStatus {
  live
  offline
}

enum EquipmentStatus {
  available
  checked_out
}

model User {
  id            String    @id @default(cuid())
  email         String    @unique
  name          String
  role          UserRole  @default(public)
  password_hash String
  created_at    DateTime  @default(now())

  burrows        Burrow[]           @relation("AssignedVolunteer")
  donations      Donation[]
  sightings      WildlifeSighting[] @relation("SightingReporter")
  event_rsvps    EventRSVP[]
  volunteer_hours VolunteerHour[]
  equipment_items EquipmentItem[]   @relation("CheckedOutBy")
  verified_hours  VolunteerHour[]   @relation("VerifiedBy")

  @@map("users")
}

model Burrow {
  id                   String       @id @default(cuid())
  gps_lat              Float
  gps_lng              Float
  status               BurrowStatus @default(active)
  location_description String?
  photos               String[]     @default([])
  assigned_volunteer_id String?
  created_at           DateTime     @default(now())

  assigned_volunteer User? @relation("AssignedVolunteer", fields: [assigned_volunteer_id], references: [id], onDelete: SetNull)

  @@map("burrows")
}

model Donation {
  id                String           @id @default(cuid())
  donor_id          String?
  amount            Float
  campaign          DonationCampaign @default(general)
  stripe_payment_id String?
  created_at        DateTime         @default(now())

  donor User? @relation(fields: [donor_id], references: [id], onDelete: SetNull)

  @@map("donations")
}

model WildlifeSighting {
  id          String   @id @default(cuid())
  reporter_id String?
  species     String
  gps_lat     Float
  gps_lng     Float
  photo_url   String?
  description String?
  verified    Boolean  @default(false)
  created_at  DateTime @default(now())

  reporter User? @relation("SightingReporter", fields: [reporter_id], references: [id], onDelete: SetNull)

  @@map("wildlife_sightings")
}

model Event {
  id             String    @id @default(cuid())
  title          String
  description    String?
  date           DateTime
  location       String
  max_attendees  Int?
  type           EventType
  created_at     DateTime  @default(now())

  rsvps EventRSVP[]

  @@map("events")
}

model EventRSVP {
  event_id   String
  user_id    String
  created_at DateTime @default(now())

  event Event @relation(fields: [event_id], references: [id], onDelete: Cascade)
  user  User  @relation(fields: [user_id], references: [id], onDelete: Cascade)

  @@id([event_id, user_id])
  @@map("event_rsvps")
}

model LivestreamSource {
  id              String       @id @default(cuid())
  name            String
  stream_url      String
  camera_location String
  status          StreamStatus @default(offline)
  thumbnail_url   String?
  created_at      DateTime     @default(now())

  @@map("livestream_sources")
}

model VolunteerHour {
  id               String   @id @default(cuid())
  volunteer_id     String
  date             DateTime
  hours            Float
  task_description String
  verified_by      String?
  created_at       DateTime @default(now())

  volunteer User  @relation(fields: [volunteer_id], references: [id], onDelete: Cascade)
  verifier  User? @relation("VerifiedBy", fields: [verified_by], references: [id], onDelete: SetNull)

  @@map("volunteer_hours")
}

model EquipmentItem {
  id             String          @id @default(cuid())
  name           String
  description    String?
  status         EquipmentStatus @default(available)
  checked_out_by String?
  checked_out_at DateTime?
  created_at     DateTime        @default(now())

  checker User? @relation("CheckedOutBy", fields: [checked_out_by], references: [id], onDelete: SetNull)

  @@map("equipment_items")
}
