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

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

model User {
  id    String  @id @default(uuid())
  email String  @unique
  admin Boolean @default(false)

  dateFormat        String @default("en-GB")
  currency          String @default("€")
  defaultHourlyRate Float?

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

  password    Password?
  timeEntries TimeEntry[]
  projects    Project[]
}

model Settings {
  id    String @id
  value String
}

model Password {
  hash String

  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  userId String @unique
}

model TimeEntry {
  id          String    @id @default(uuid())
  description String
  startTime   DateTime  @default(now())
  endTime     DateTime?
  duration    Float?

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

  project   Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  projectId String

  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  userId String
}

model Project {
  id          String  @id @default(uuid())
  name        String
  description String?
  color       String

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

  timeEntries TimeEntry[]

  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  userId String
}
