// 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"
  output   = "../node_modules/.prisma/client"
}

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

model User {
  id      Int      @id @default(autoincrement())
  userId  String   @unique   
  email   String   @unique
  name    String?
  role    Role     @default(USER)
  posts   Post[]
  profile Profile?
  username   String   @unique
  avatar     String?
  password   String
  birthdate  DateTime?
  registeredAt DateTime?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Profile {
  id     Int    @id @default(autoincrement())
  bio    String
  avatar String?
  // user   User   @relation(fields: [userId], references: [id])
  // userId Int    @unique
  user   User   @relation(fields: [userId], references: [userId]) // reference userId UUID
  userId String @unique
}

model Post {
  id         Int        @id @default(autoincrement())
  title      String
  content    String?
  published  Boolean    @default(false)
  author     User       @relation(fields: [authorId], references: [id])
  authorId   Int
  createdAt  DateTime   @default(now())
  updatedAt  DateTime   @updatedAt
}


enum Role {
  USER
  EDITOR
  ADMIN
}
