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

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

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

model User {
  id            String    @id @default(uuid())
  username      String    @unique
  image         String?
  email         String    @unique
  disabled      Boolean   @default(false)
  password      String
  role          Role      @default(USER)
  createdAt     DateTime  @default(now()) @map("created_at")
  emailVerified DateTime? @map("email_verified")
  invitedBy     String?   @map("invited_by")
  apiKey        String    @unique @default(cuid()) @map("api_key")
  uploadLimit   Int       @default(500) @map("upload_limit")

  embed_settings EmbedSettings?
  files          File[]

  @@map("users")
}

model EmbedSettings {
  id            String  @id @default(cuid())
  enabled       Boolean @default(false)
  provider_name String?
  provider_url  String?
  author_name   String?
  author_url    String?
  title         String?
  description   String?
  color         String

  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId String @unique @map("user_id")

  @@map("embed_settings")
}

model File {
  id        String   @id @default(cuid())
  filename  String
  mimetype  String
  slug      String   @unique
  size      Int
  createdAt DateTime @default(now()) @map("created_at")
  views     Int      @default(0)

  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId String @map("user_id")

  @@unique([userId, slug])
  @@map("files")
}

enum Role {
  OWNER
  ADMIN
  USER
}
