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

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

model audit {
  auditID          Int       @id @default(autoincrement())
  auditIP          String?   @db.VarChar(255)
  auditURL         String?   @db.VarChar(255)
  auditURLMethod   String?   @db.VarChar(255)
  auditURLPayload  String?   @db.Text
  auditCreatedDate DateTime? @default(now()) @db.DateTime(0)
  auditAction      String?   @db.VarChar(255)
  auditDetails     String?   @db.Text
  auditUserID      Int?
  auditUsername    String?   @db.VarChar(255)
  user             user?     @relation(fields: [auditUserID], references: [userID])

  @@index([auditUserID], map: "FK_audit_user")
}

model organization {
  org_id       Int          @id @default(autoincrement())
  org_name     String       @unique(map: "organization_unique") @db.VarChar(255)
  org_address1 String?      @db.VarChar(255)
  org_address2 String?      @db.VarChar(255)
  org_postcode Int?
  org_state    String?      @db.VarChar(100)
  org_country  String?      @db.VarChar(100)
  org_active   Int?
  departments  department[]
}

model department {
  dp_id        Int          @id @default(autoincrement())
  dp_name      String       @db.VarChar(255)
  org_id       Int
  cabinets     cabinets[]
  organization organization @relation(fields: [org_id], references: [org_id], onDelete: Cascade, onUpdate: NoAction, map: "department_organization_FK")
  user         user[]

  @@index([org_id], map: "department_organization_FK")
}

model cabinets {
  cb_id        Int         @id @default(autoincrement())
  cb_name      String      @unique(map: "cabinet_master_unique") @db.VarChar(255)
  cb_parent_id Int?
  cb_owner     Int?
  cb_sector    String      @db.VarChar(7)
  dp_id        Int?
  userID       Int?
  created_at   DateTime?   @db.DateTime(0)
  modified_at  DateTime?   @db.DateTime(0)
  department   department? @relation(fields: [dp_id], references: [dp_id], onDelete: NoAction, onUpdate: NoAction, map: "cabinets_department_FK")
  user         user?       @relation(fields: [userID], references: [userID], onDelete: NoAction, onUpdate: NoAction, map: "cabinets_user_FK")

  @@index([dp_id], map: "cabinets_department_FK")
  @@index([userID], map: "cabinets_user_FK")
}

model role {
  roleID           Int        @id @default(autoincrement())
  roleName         String?    @db.VarChar(255)
  roleDescription  String?    @db.VarChar(255)
  roleStatus       String?    @db.VarChar(255)
  roleCreatedDate  DateTime?  @db.DateTime(0)
  roleModifiedDate DateTime?  @db.DateTime(0)
  userrole         userrole[]
}

model user {
  userID           Int         @id @default(autoincrement())
  userSecretKey    String?     @db.VarChar(255)
  userUsername     String?     @db.VarChar(255)
  userPassword     String?     @db.VarChar(255)
  userFullName     String?     @db.VarChar(255)
  userEmail        String?     @db.VarChar(255)
  userPhone        String?     @db.VarChar(255)
  userStatus       String?     @db.VarChar(255)
  dp_id            Int?
  userCreatedDate  DateTime?   @db.DateTime(0)
  userModifiedDate DateTime?   @db.DateTime(0)
  audit            audit[]
  cabinets         cabinets[]
  department       department? @relation(fields: [dp_id], references: [dp_id], onDelete: NoAction, onUpdate: NoAction, map: "user_department_FK")
  userrole         userrole[]

  @@index([dp_id], map: "user_department_FK")
}

model userrole {
  userRoleID          Int      @id @default(autoincrement())
  userRoleUserID      Int      @default(0)
  userRoleRoleID      Int      @default(0)
  userRoleCreatedDate DateTime @db.DateTime(0)
  role                role     @relation(fields: [userRoleRoleID], references: [roleID], onDelete: NoAction, onUpdate: NoAction, map: "FK_userrole_role")
  user                user     @relation(fields: [userRoleUserID], references: [userID], onDelete: NoAction, onUpdate: NoAction, map: "FK_userrole_user")

  @@index([userRoleRoleID], map: "FK_userrole_role")
  @@index([userRoleUserID], map: "FK_userrole_user")
}

model dms_settings {
  settingID                     Int       @id @default(autoincrement())
  userRoles                     String?   @db.Text
  rbacEnabled                   Boolean?  @default(true)
  userGroups                    String?   @db.Text
  permissionView                Boolean?  @default(true)
  permissionEdit                Boolean?  @default(true)
  permissionDelete              Boolean?  @default(false)
  permissionDownload            Boolean?  @default(true)
  permissionShare               Boolean?  @default(true)
  ssoEnabled                    Boolean?  @default(false)
  mfaRequired                   Boolean?  @default(false)
  ldapIntegration               Boolean?  @default(false)
  sessionTimeout                Int?      @default(8)
  folderMaxDepth                Int?      @default(5)
  folderDefaultStructure        String?   @db.Text
  folderTemplates               String?   @db.Text
  namingAutoGenerate            Boolean?  @default(true)
  namingMandatoryFields         String?   @db.Text
  namingPattern                 String?   @default("{department}_{title}_{date}") @db.VarChar(255)
  retentionEnabled              Boolean?  @default(true)
  retentionDefaultDays          Int?      @default(2555)
  retentionArchiveBeforeDelete  Boolean?  @default(true)
  versionControlEnabled         Boolean?  @default(true)
  versionControlMaxVersions     Int?      @default(10)
  versionControlAutoVersioning  Boolean?  @default(true)
  metadataCustomFields          String?   @db.LongText
  taggingPredefinedTags         String?   @db.Text
  taggingUserGeneratedTags      Boolean?  @default(true)
  taggingTagSuggestions         Boolean?  @default(true)
  classificationAutoEnabled     Boolean?  @default(true)
  classificationRules           String?   @db.Text
  workflowApprovalEnabled       Boolean?  @default(true)
  workflowDefaultFlow           String?   @default("department-head-approval") @db.VarChar(255)
  workflowCustomFlows           String?   @db.Text
  notificationEmail             Boolean?  @default(true)
  notificationInApp             Boolean?  @default(true)
  notificationUploadAlerts      Boolean?  @default(true)
  notificationDeadlineReminders Boolean?  @default(true)
  automationTriggers            String?   @db.Text
  automationActions             String?   @db.Text
  uploadAllowedFileTypes        String?   @db.Text
  uploadBlockedFileTypes        String?   @db.Text
  uploadFileSizeLimit           Int?      @default(100)
  uploadQuotaPerUser            Int?      @default(5000)
  uploadQuotaPerGroup           Int?      @default(50000)
  uploadQuotaPerProject         Int?      @default(100000)
  storageType                   String?   @default("local") @db.VarChar(100)
  storagePath                   String?   @default("/var/uploads/edms") @db.VarChar(500)
  storageBackupEnabled          Boolean?  @default(true)
  storageCompressionEnabled     Boolean?  @default(false)
  systemTimezone                String?   @default("Asia/Kuala_Lumpur") @db.VarChar(100)
  systemBackupSchedule          String?   @default("daily") @db.VarChar(100)
  systemLogLevel                String?   @default("info") @db.VarChar(100)
  systemMaintenanceMode         Boolean?  @default(false)
  systemAutoUpdates             Boolean?  @default(false)
  systemMonitoring              Boolean?  @default(true)
  systemPerformanceMetrics      Boolean?  @default(true)
  settingCreatedDate            DateTime? @default(now()) @db.DateTime(0)
  settingModifiedDate           DateTime? @default(now()) @db.DateTime(0)
}

model site_settings {
  settingID            Int       @id @default(autoincrement())
  siteName             String?   @default("corradAF") @db.VarChar(255)
  siteNameFontSize     Int?      @default(18)
  siteDescription      String?   @db.Text
  siteLogo             String?   @db.VarChar(500)
  siteLoadingLogo      String?   @db.VarChar(500)
  siteFavicon          String?   @db.VarChar(500)
  siteLoginLogo        String?   @db.VarChar(500)
  showSiteNameInHeader Boolean?  @default(true)
  customCSS            String?   @db.LongText
  themeMode            String?   @default("biasa") @db.VarChar(100)
  customThemeFile      String?   @db.VarChar(500)
  currentFont          String?   @db.VarChar(100)
  fontSource           String?   @db.VarChar(100)
  seoTitle             String?   @db.VarChar(255)
  seoDescription       String?   @db.Text
  seoKeywords          String?   @db.Text
  seoAuthor            String?   @db.VarChar(255)
  seoOgImage           String?   @db.VarChar(500)
  seoTwitterCard       String?   @default("summary_large_image") @db.VarChar(100)
  seoCanonicalUrl      String?   @db.VarChar(500)
  seoRobots            String?   @default("index, follow") @db.VarChar(100)
  seoGoogleAnalytics   String?   @db.VarChar(255)
  seoGoogleTagManager  String?   @db.VarChar(255)
  seoFacebookPixel     String?   @db.VarChar(255)
  settingCreatedDate   DateTime? @default(now()) @db.DateTime(0)
  settingModifiedDate  DateTime? @default(now()) @db.DateTime(0)
}
