generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

model tokens {
  id        String    @id
  token     String    @unique
  type      TokenType
  userId    String
  expiresAt DateTime
  createdAt DateTime  @default(now())
  users     users     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model users {
  id           String   @id
  name         String
  email        String   @unique
  password     String
  profilePhoto String?  @default("")
  bio          String?  @default("")
  createdAt    DateTime @default(now())
  updatedAt    DateTime
  rides        rides[]
  tokens       tokens[]

  @@index([email], map: "idx_users_email")
}

model companies {
  id          String    @id
  name        String
  cost_per_km Decimal   @db.Decimal(10, 2)
  notes       String?   @default("")
  createdAt   DateTime? @default(now()) @db.Timestamptz(6)
  updatedAt   DateTime? @default(now()) @db.Timestamptz(6)

  @@index([name], map: "idx_companies_name")
}

model rides {
  id          String    @id
  user_id     String
  company     String
  km          Decimal   @db.Decimal(10, 2)
  cost_per_km Decimal   @db.Decimal(10, 2)
  total       Decimal   @db.Decimal(10, 2)
  ride_date   String
  synced      Int?      @default(0) @db.SmallInt
  createdAt   DateTime? @default(now()) @db.Timestamptz(6)
  updatedAt   DateTime? @default(now()) @db.Timestamptz(6)
  users       users     @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

  @@index([synced], map: "idx_rides_synced")
  @@index([user_id], map: "idx_rides_user_id")
}

enum TokenType {
  REFRESH
}
