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

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

model User {
  id                       String          @id @default(cuid())
  name                     String?
  email                    String?         @unique
  password                 String?
  emailVerified            DateTime?
  verificationToken        String?         @unique
  verificationTokenExpires DateTime?
  image                    String?
  createdAt                DateTime        @default(now())
  updatedAt                DateTime        @updatedAt
  accounts                 Account[]
  Authenticator            Authenticator[]
  profile                  Profile?
  sessions                 Session[]
}

model Profile {
  id                    String              @id @default(cuid())
  userId                String              @unique
  location              String?
  description           String?
  contactInfo           String?
  birthYear             Int?
  occupation            String?
  gender                Gender?
  personalityType       PersonalityType?
  introversion          Int?
  conflictStyle         ConflictStyle?
  images                String[]
  user                  User                @relation(fields: [userId], references: [id], onDelete: Cascade)
  causeAreas            ProfileCauseArea[]
  desiredConnections    ProfileConnection[]
  intellectualInterests ProfileInterest[]
  coreValues            ProfileValue[]
  books                 ProfileBook[]
  promptAnswers         PromptAnswer[]
}

model Connection {
  id    String              @id @default(cuid())
  name  String              @unique
  users ProfileConnection[]
}

model Interest {
  id    String            @id @default(cuid())
  name  String            @unique
  users ProfileInterest[]
}

model Value {
  id    String         @id @default(cuid())
  name  String         @unique
  users ProfileValue[]
}

model Book {
  id    String         @id @default(cuid())
  name  String         @unique
  users ProfileBook[]
}

model CauseArea {
  id    String             @id @default(cuid())
  name  String             @unique
  users ProfileCauseArea[]
}

model ProfileConnection {
  profileId    String
  connectionId String
  connection   Connection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
  profile      Profile    @relation(fields: [profileId], references: [id], onDelete: Cascade)

  @@id([profileId, connectionId])
}

model ProfileInterest {
  profileId  String
  interestId String
  interest   Interest @relation(fields: [interestId], references: [id], onDelete: Cascade)
  profile    Profile  @relation(fields: [profileId], references: [id], onDelete: Cascade)

  @@id([profileId, interestId])
}

model ProfileValue {
  profileId String
  valueId   String
  value     Value   @relation(fields: [valueId], references: [id], onDelete: Cascade)
  profile   Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)

  @@id([profileId, valueId])
}

model ProfileBook {
  profileId String
  valueId   String
  value     Book   @relation(fields: [valueId], references: [id], onDelete: Cascade)
  profile   Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)

  @@id([profileId, valueId])
}

model ProfileCauseArea {
  profileId   String
  causeAreaId String
  causeArea   CauseArea @relation(fields: [causeAreaId], references: [id], onDelete: Cascade)
  profile     Profile   @relation(fields: [profileId], references: [id], onDelete: Cascade)

  @@id([profileId, causeAreaId])
}

model PromptAnswer {
  id        String  @id @default(cuid())
  profileId String
  prompt    String
  answer    String
  profile   Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
}

model Account {
  id                String   @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?
  access_token      String?
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?
  session_state     String?
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt
  user              User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

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

model VerificationToken {
  identifier String
  token      String
  expires    DateTime

  @@unique([identifier, token])
}

model Authenticator {
  credentialID         String  @unique
  userId               String
  providerAccountId    String
  credentialPublicKey  String
  counter              Int
  credentialDeviceType String
  credentialBackedUp   Boolean
  transports           String?
  user                 User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@id([userId, credentialID])
}

enum Gender {
  Man
  Woman
  Other
}

enum PersonalityType {
  Introvert
  Extrovert
  Ambivert
}

enum ConflictStyle {
  Competing
  Avoidant
  Compromising
  Accommodating
  Collaborating
}
