// 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"
  binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}

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

enum FundSlug {
  monero
  firo
  privacyguides
  general
}

enum AccountConnectionType {
  privacyGuidesForum
}

enum MembershipTerm {
  monthly
  annually
}

model Donation {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  userId                     String?
  donorName                  String?
  donorNameIsProfane         Boolean?        @default(false)
  btcPayInvoiceId            String?         @unique
  stripePaymentIntentId      String?         @unique // For donations and non-recurring memberships
  stripeInvoiceId            String?         @unique // For recurring memberships
  stripeSubscriptionId       String? // For recurring memberships
  coinbaseChargeId           String?         @unique
  projectSlug                String
  projectName                String
  fundSlug                   FundSlug
  cryptoPayments             Json?
  grossFiatAmount            Float
  netFiatAmount              Float
  pointsAdded                Int             @default(0)
  membershipExpiresAt        DateTime?
  membershipTerm             MembershipTerm?
  showDonorNameOnLeaderboard Boolean?        @default(false)

  cryptoCode        String?
  grossCryptoAmount String?
  netCryptoAmount   String?

  @@index([btcPayInvoiceId])
  @@index([stripePaymentIntentId])
  @@index([stripeSubscriptionId])
  @@index([userId])
}

model ProjectAddresses {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  projectSlug     String
  fundSlug        FundSlug
  btcPayInvoiceId String
  bitcoinAddress  String?
  moneroAddress   String?
  litecoinAddress String?

  @@unique([projectSlug, fundSlug])
}

model AccountConnection {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  type                                AccountConnectionType
  userId                              String
  externalId                          String
  privacyGuidesAccountIsInMemberGroup Boolean?

  @@index([userId])
  @@index([externalId])
}
