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

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

model User {
  id            String   @id @default(uuid()) @db.Uuid
  email         String   @unique
  passwordHash  String   @map("password_hash")
  name          String

  @@map("users")
}

model Project {
  id            String         @id @default(uuid()) @db.Uuid
  title         String
  slug          String         @unique
  description   String         @db.Text
  imageUrl      String?        @map("image_url")
  imageUrls     String[]       @default([]) @map("image_urls")
  repoUrl       String?        @map("repo_url")
  liveUrl       String?        @map("live_url")
  category      String
  isPublished   Boolean        @default(false) @map("is_published")
  createdAt     DateTime       @default(now()) @map("created_at")
  
  techStack     String[]
  year          Int?
  highlights    String[]

  skills        ProjectSkill[]

  @@map("projects")
}

model Skill {
  id            String         @id @default(uuid()) @db.Uuid
  name          String
  iconName      String?        @map("icon_name")
  category      String
  sortOrder     Int            @default(0) @map("sort_order")
  
  projects      ProjectSkill[]

  @@map("skills")
}

// Explicit Join Table based on ERD
model ProjectSkill {
  projectId     String   @map("project_id") @db.Uuid
  skillId       String   @map("skill_id") @db.Uuid
  
  project       Project  @relation(fields: [projectId], references: [id], onDelete: Cascade)
  skill         Skill    @relation(fields: [skillId], references: [id], onDelete: Cascade)

  @@id([projectId, skillId])
  @@map("project_skills")
}

model Message {
  id            String   @id @default(uuid()) @db.Uuid
  senderName    String   @map("sender_name")
  senderEmail   String   @map("sender_email")
  content       String   @db.Text
  isRead        Boolean  @default(false) @map("is_read")
  createdAt     DateTime @default(now()) @map("created_at")

  @@map("messages")
}

model Experience {
  id            String   @id @default(uuid()) @db.Uuid
  year          String
  title         String
  company       String
  description   String   @db.Text
  achievements  Json     @default("[]")
  order         Int      @default(0)
  createdAt     DateTime @default(now()) @map("created_at")

  @@map("experiences")
}

model Education {
  id                String   @id @default(uuid()) @db.Uuid
  institution       String
  degree            String
  fieldOfStudy      String   @map("field_of_study")
  location          String?
  startYear         Int      @map("start_year")
  endYear           Int?     @map("end_year")
  isOngoing         Boolean  @default(false) @map("is_ongoing")
  description       String?  @db.Text
  gpa               String?
  finalProjectTitle String?  @map("final_project_title")
  finalProjectUrl   String?  @map("final_project_url")
  order             Int      @default(0)
  createdAt         DateTime @default(now()) @map("created_at")

  @@map("educations")
}
