# Schema Overview

## Основни домейни

### 1. Каталожни lookup таблици

- `currencies`
- `property_types`
- `deal_types`
- `property_statuses`
- `location_types`
- `media_types`
- `inquiry_types`
- `inquiry_statuses`
- `page_types`

Тези таблици осигуряват строга валидация на enum-подобните стойности и позволяват seed/управление без hardcoded стойности в приложението.

### 2. Административни и системни обекти

- `admin_users`
- `audit_logs`
- `site_documents`

`site_documents` покрива системни текстови артефакти като `llms.txt`, а `audit_logs` пази критична проследимост на административните промени.

### 3. GEO / SEO / Локации

- `locations`
- `offices`
- `seo_metadata`
- `landing_pages`

`locations` е self-referencing дърво чрез `parent_id`, което позволява държава → регион → град → район → подрайон.

### 4. Имоти

- `properties`
- `property_media`
- `property_custom_field_values`
- `property_custom_field_multi_values`

Схемата е нормализирана за основните данни на имота и достатъчно гъвкава за бъдещо разширяване към history tables, imports и external feeds.

### 5. Custom fields

- `custom_field_groups`
- `custom_field_definitions`
- `custom_field_options`
- `property_custom_field_values`
- `property_custom_field_multi_values`

Това е хибриден модел: стабилните бизнес критични данни остават в `properties`, а променливите по тип имот характеристики минават през dynamic schema layer.

### 6. Съдържание

- `pages`
- `blog_posts`
- `blog_categories`
- `blog_tags`
- `blog_post_categories`
- `blog_post_tags`
- `faqs`

Тези таблици покриват статични страници, FAQ, блог и SEO landing pages.

### 7. Запитвания

- `inquiries`
- `inquiry_logs`

`inquiry_logs` позволява проследяване на статуса и вътрешната обработка.

## Ключови релации

- `properties.property_type_id -> property_types.id`
- `properties.deal_type_id -> deal_types.id`
- `properties.status_id -> property_statuses.id`
- `properties.location_id -> locations.id`
- `properties.office_id -> offices.id`
- `property_media.property_id -> properties.id`
- `inquiries.property_id -> properties.id`
- `inquiries.office_id -> offices.id`
- `custom_field_groups.property_type_id -> property_types.id`
- `custom_field_definitions.property_type_id -> property_types.id`
- `custom_field_definitions.group_id -> custom_field_groups.id`
- `custom_field_options.field_definition_id -> custom_field_definitions.id`
- `property_custom_field_values.property_id -> properties.id`
- `property_custom_field_values.field_definition_id -> custom_field_definitions.id`
- `property_custom_field_multi_values.option_id -> custom_field_options.id`
- `faqs.page_id -> pages.id`
- `landing_pages.page_id -> pages.id`

## Специални бележки

- `seo_metadata` е централен polymorphic SEO слой с уникалност по `(entity_type, entity_id)`.
- `properties`, `pages` и `blog_posts` имат `search_vector` за бъдещо full text search.
- `deleted_at` е предвиден там, където soft delete е бизнес обоснован.
