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

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

model User {
  id            String    @id @default(cuid())
  email         String    @unique
  passwordHash  String
  name          String?
  company       String?
  role          UserRole  @default(USER)
  apiKey        String?   @unique
  isActive      Boolean   @default(true)
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  
  websites      Website[]
  reports       Report[]
  scanJobs      ScanJob[]
}

model Website {
  id               String           @id @default(cuid())
  name             String
  url              String
  userId           String
  user             User             @relation(fields: [userId], references: [id])
  
  scanSchedule     Json?            // ScanSchedule type
  lastScanAt       DateTime?
  complianceScore  Float?
  tags             String[]
  active           Boolean          @default(true)
  
  authConfig       Json?            // AuthenticationConfig type
  scanOptions      Json?            // Default scan options
  
  createdAt        DateTime         @default(now())
  updatedAt        DateTime         @updatedAt
  
  scanResults      ScanResult[]
  scanJobs         ScanJob[]
  reports          Report[]
  
  @@index([userId])
  @@index([url])
}

model ScanResult {
  id              String    @id @default(cuid())
  websiteId       String
  website         Website   @relation(fields: [websiteId], references: [id])
  jobId           String?   @unique
  job             ScanJob?  @relation(fields: [jobId], references: [id])
  
  url             String
  scanDuration    Int
  summary         Json      // ScanSummary type
  violations      Json      // AccessibilityViolation[] type
  passes          Json      // AxeResult[] type
  incomplete      Json      // AxeResult[] type
  inapplicable    Json      // AxeResult[] type
  pageMetadata    Json      // PageMetadata type
  wcagCompliance  Json      // WCAGCompliance type
  
  createdAt       DateTime  @default(now())
  
  @@index([websiteId])
  @@index([createdAt])
}

model ScanJob {
  id            String        @id @default(cuid())
  websiteId     String
  website       Website       @relation(fields: [websiteId], references: [id])
  userId        String
  user          User          @relation(fields: [userId], references: [id])
  
  url           String
  status        JobStatus     @default(PENDING)
  options       Json          // AccessibilityScanOptions type
  
  scheduledAt   DateTime      @default(now())
  startedAt     DateTime?
  completedAt   DateTime?
  
  error         String?
  retryCount    Int           @default(0)
  maxRetries    Int           @default(3)
  
  result        ScanResult?
  
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt
  
  @@index([websiteId])
  @@index([status])
  @@index([scheduledAt])
}

model Report {
  id            String    @id @default(cuid())
  websiteId     String
  website       Website   @relation(fields: [websiteId], references: [id])
  userId        String
  user          User      @relation(fields: [userId], references: [id])
  
  type          ReportType
  format        ReportFormat
  period        Json      // ReportPeriod type
  
  summary       Json      // ReportSummary type
  data          Json      // Report data
  
  fileUrl       String?
  
  generatedAt   DateTime  @default(now())
  
  @@index([websiteId])
  @@index([userId])
  @@index([generatedAt])
}

enum UserRole {
  USER
  ADMIN
}

enum JobStatus {
  PENDING
  RUNNING
  COMPLETED
  FAILED
}

enum ReportType {
  COMPLIANCE
  EXECUTIVE
  TECHNICAL
  TREND
}

enum ReportFormat {
  PDF
  HTML
  JSON
  CSV
}