@startuml
title MaaS — сущности и поля (MongoDB документы)

hide circle
skinparam linetype ortho

entity "maas.organizations\n(MaasOrganization)" as Organization {
  == Идентификаторы ==
  _id: string  <<= owner_id>>
  owner_id: string

  == Данные ==
  name: string
  violations: string[]  (опц.)

  == Служебные поля ==
  created_at: int  <<unix ts>>
  updated_at: int  (опц.)
  deleted: bool
  deleted_at: int  (опц.)
}

entity "maas.facilities\n(MaasFacility)" as Facility {
  _id: string
  organization_id: string
  owner_id: string

  name: string
  timezone: string  <<IANA>>
  camera_ids: string[]

  created_at: int  <<unix ts>>
  updated_at: int  (опц.)
  deleted: bool
  deleted_at: int  (опц.)
}

entity "maas.checklists\n(MaasChecklist)" as Checklist {
  _id: string
  organization_id: string
  owner_id: string

  name: string
  type: enum('process','state')
  priority: enum('medium','high') (опц.)
  description: string (опц.)
  enabled: bool
  include_violations: bool

  schedule: Schedule
  sources: Source[]
  questions: Question[]

  _marks: map<string,int>  <<facility_id -> last_gen_ts>> (опц.)

  created_at: int  <<unix ts>>
  updated_at: int  (опц.)
  deleted: bool
  deleted_at: int  (опц.)
}

entity "maas.review_tasks\n(MaasReviewTask)" as ReviewTask {
  _id: string
  organization_id: string
  owner_id: string

  checklist_id: string
  sources: Source           <<ровно один Source>>
  type: enum('process','state')
  status: enum('open','in_progress','closed'?)*   // в коде используются 'open','in_progress'
  assignee_id: string  <<'NOT_SET' или user_id>>

  interval: int[2]  <<[start_ts,end_ts]>>
  questions: Question[]   <<snapshot из чек-листа>>
  checklist: dict         <<snapshot>>
  facility: dict          <<snapshot>>

  violations: any[]       <<пока пустой список>>
  created_at: int         <<unix ts>>
  updated_at: int  (опц.)
  deleted: bool
}

' --- Вложенные типы ---
entity "Schedule" as Schedule {
  intervals: Interval[]
}
entity "Interval" as Interval {
  start_weekday: string <<'Monday'..'Sunday'>>
  start_time: string    <<'HH:mm:ss'>>
  end_weekday: string
  end_time: string
}

entity "Source" as Source {
  facility: string <<facility_id>>
  cameras: string[] <<camera_id>>
}

entity "Question" as Question {
  description_text: string
  instruction_text: string (опц.)
  description_image_url: string (опц.)
  // во время/после ревью могут добавляться:
  // comment: string (опц.)
  // proof_image_url: string (опц.)
}

Organization ||--o{ Facility : "1:N"
Organization ||--o{ Checklist : "1:N"
Checklist }o--o{ Facility : "M:N через sources"
Checklist ||--o{ ReviewTask : "по расписанию"
Facility ||--o{ ReviewTask : "через sources"
@enduml
