// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

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

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

model user {
  id   Int    @id @unique @default(autoincrement())
  name String @unique
  code String?

  // TODO: Prüfen ob nötig, erstmal vorbereitet.
  transactions transactions[]

  @@fulltext([name])
}

model transactions {
  id Int @id @unique @default(autoincrement())

  sales sales[]

  user   user @relation(fields: [userId], references: [id])
  userId Int

  total Float
  paid      Boolean @default(false)
  paidAt    Boolean?
  createdAt DateTime @default(now())

}

model sales {
  id             Int          @id @unique @default(autoincrement())
  transactions   transactions @relation(fields: [transactionsId], references: [id])
  transactionsId Int

  product   products? @relation(fields: [productId], references: [id])
  productId Int?

  price    Float
}

model products {
  id   Int    @id @unique @default(autoincrement())
  gtin String @unique // Dont try to use BigInt -> https://github.com/prisma/studio/issues/614
  name String @unique
  price Decimal @db.Decimal(5,2) // FIXME: input:  77.80 -> output: 77.8
  stock Int
  visible Boolean @default(true)

  sales   sales[]

  @@fulltext([name])
}
