generator dartClient {
  provider = "dart run orm"
  output   = "../lib/infrastructure/persistence/db"
}

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

// User Model
model UserDbo {
  id          String      @id @default(uuid())
  name        String
  email       String      @unique
  password    String
  projects    ProjectDbo[] // Beziehung zu Projekten
  timeEntries TimeEntryDbo[] // Beziehung zu Zeiteinträgen
  createdAt   DateTime    @default(now())
  updatedAt   DateTime    @updatedAt
}

// Project Model
model ProjectDbo {
  id          String      @id @default(uuid())
  name        String
  description String?
  clientId    String?
  tasks       ProjectTaskDbo[] // Beziehung zu Aufgaben
  timeEntries TimeEntryDbo[] // Beziehung zu Zeiteinträgen
  user        UserDbo        @relation(fields: [userId], references: [id])
  userId      String
  createdAt   DateTime    @default(now())
  updatedAt   DateTime    @updatedAt
}

// TimeEntry Model
model TimeEntryDbo {
  id          String   @id @default(uuid())
  startTime   DateTime
  endTime     DateTime?
  description String?
  user        UserDbo     @relation(fields: [userId], references: [id])
  userId      String
  project     ProjectDbo  @relation(fields: [projectId], references: [id])
  projectId   String
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

// Task Model (optional)
model ProjectTaskDbo {
  id          String   @id @default(uuid())
  name        String
  description String?
  project     ProjectDbo  @relation(fields: [projectId], references: [id])
  projectId   String
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}
