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

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

model Document {
  id        Int         @id @default(autoincrement())
  userId    Int
  document  Bytes?
  User      User        @relation(fields: [userId], references: [id], onDelete: Cascade)
  Recipient Recipient[]
}

model Recipient {
  id            Int           @id @default(autoincrement())
  documentId    Int
  email         String        @db.VarChar(255)
  readStatus    ReadStatus
  signingStatus SigningStatus
  sendStatus    SendStatus
  Document      Document      @relation(fields: [documentId], references: [id], onDelete: Cascade)
}

model User {
  id               Int              @id @default(autoincrement())
  name             String?
  email            String           @unique
  emailVerified    DateTime?
  password         String?
  identityProvider IdentityProvider @default(DOCUMENSO)
  accounts         Account[]
  sessions         Session[]
  Document         Document[]
}

model Account {
  id                String  @id @default(cuid())
  userId            Int
  type              String
  provider          String
  providerAccountId String
  refresh_token     String? @db.Text
  access_token      String? @db.Text
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String? @db.Text
  session_state     String?

  user User? @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       Int
  expires      DateTime
  user         User?    @relation(fields: [userId], references: [id], onDelete: Cascade)
}

enum IdentityProvider {
  DOCUMENSO
  GOOGLE
}

enum ReadStatus {
  NOT_OPENED
  OPENED
}

enum SendStatus {
  NOT_SENT
  SENT
}

enum SigningStatus {
  NOT_SIGNED
  SIGNED
}
