@startuml ERD-회의종료
!theme mono

' ========================================
' 회의종료 기능 ERD
' ========================================

!define TABLE(name,desc) class name as "desc" << (T,#FFAAAA) >>
!define PRIMARY_KEY(x) <b>PK: x</b>
!define FOREIGN_KEY(x) <i>FK: x</i>
!define NOT_NULL(x) <u>x</u>
!define UNIQUE(x) <color:blue>x</color>

' 기존 테이블
TABLE(meetings, "meetings\n회의") {
  PRIMARY_KEY(meeting_id: VARCHAR(50))
  --
  title: VARCHAR(200)
  start_time: TIMESTAMP
  end_time: TIMESTAMP
  status: VARCHAR(20)
  created_at: TIMESTAMP
  updated_at: TIMESTAMP
}

TABLE(meeting_participants, "meeting_participants\n회의 참석자") {
  PRIMARY_KEY(meeting_id, user_id)
  --
  FOREIGN_KEY(meeting_id: VARCHAR(50))
  FOREIGN_KEY(user_id: VARCHAR(100))
  invitation_status: VARCHAR(20)
  attended: BOOLEAN
  created_at: TIMESTAMP
}

' 확장된 minutes 테이블
TABLE(minutes, "minutes\n회의록") {
  PRIMARY_KEY(id: VARCHAR(36))
  --
  FOREIGN_KEY(meeting_id: VARCHAR(50))
  content: TEXT
  NOT_NULL(user_id: VARCHAR(100))
  NOT_NULL(is_consolidated: BOOLEAN)
  consolidated_by: VARCHAR(255)
  section_type: VARCHAR(50)
  created_at: TIMESTAMP
  updated_at: TIMESTAMP
}

' 신규 테이블: agenda_sections
TABLE(agenda_sections, "agenda_sections\n안건별 섹션") {
  PRIMARY_KEY(id: VARCHAR(36))
  --
  FOREIGN_KEY(minutes_id: VARCHAR(36))
  FOREIGN_KEY(meeting_id: VARCHAR(50))
  NOT_NULL(agenda_number: INT)
  NOT_NULL(agenda_title: VARCHAR(200))
  ai_summary_short: TEXT
  discussions: TEXT
  decisions: JSON
  pending_items: JSON
  opinions: JSON
  created_at: TIMESTAMP
  updated_at: TIMESTAMP
}

' 신규 테이블: ai_summaries
TABLE(ai_summaries, "ai_summaries\nAI 요약 캐시") {
  PRIMARY_KEY(id: VARCHAR(36))
  --
  FOREIGN_KEY(meeting_id: VARCHAR(50))
  NOT_NULL(summary_type: VARCHAR(50))
  NOT_NULL(source_minutes_ids: JSON)
  NOT_NULL(result: JSON)
  processing_time_ms: INT
  model_version: VARCHAR(50)
  keywords: JSON
  statistics: JSON
  created_at: TIMESTAMP
}

' 확장된 todos 테이블
TABLE(todos, "todos\n할일") {
  PRIMARY_KEY(id: VARCHAR(36))
  --
  FOREIGN_KEY(meeting_id: VARCHAR(50))
  content: TEXT
  assignee: VARCHAR(100)
  due_date: DATE
  priority: VARCHAR(20)
  status: VARCHAR(20)
  NOT_NULL(extracted_by: VARCHAR(50))
  section_reference: VARCHAR(200)
  extraction_confidence: DECIMAL(3,2)
  created_at: TIMESTAMP
  updated_at: TIMESTAMP
}

' 관계 정의
meetings "1" --> "N" minutes : "has"
meetings "1" --> "N" meeting_participants : "has"
meetings "1" --> "N" agenda_sections : "has"
meetings "1" --> "N" ai_summaries : "has"
meetings "1" --> "N" todos : "has"

minutes "1" --> "N" agenda_sections : "contains"
minutes "1" ..> "1" meeting_participants : "written by\n(user_id)"

' 노트 추가
note right of minutes
  **참석자별 회의록**
  - is_consolidated = false
  - section_type = 'PARTICIPANT'
  - user_id: 작성자

  **AI 통합 회의록**
  - is_consolidated = true
  - section_type = 'CONSOLIDATED'
  - user_id: NULL
end note

note right of agenda_sections
  **JSON 필드 구조**
  - decisions: ["결정1", "결정2"]
  - pending_items: ["보류1"]
  - opinions: [
      {"speaker": "김민준", "opinion": "..."}
    ]
end note

note right of ai_summaries
  **summary_type**
  - CONSOLIDATED: 통합 요약
  - TODO_EXTRACTION: Todo 추출

  **캐싱 전략**
  - 재조회 시 DB 우선 조회
  - 처리 시간 <0.5초
end note

note right of todos
  **extracted_by**
  - AI: AI 자동 추출
  - MANUAL: 사용자 수동 작성

  **extraction_confidence**
  - 0.00 ~ 1.00
  - 0.80 이상: 신뢰도 높음
end note

@enduml
