# Профили интеграции

Документ фиксирует baseline интеграционных профилей swine-пакета по шаблону `adapter-profile-template.md`.

## 1. Профиль A: климат-контроллер корпуса

- `adapter_profile_id`: `swine-bigfarmnet-climatepro-v1`
- `industry_code`: `swine`
- `module_id`: `industry.swine.climate`
- `source_type`: `controller`
- `version`: `1.0.0`
- `status`: `draft`
- `protocol`: `mqtt`
- `payload_format`: `json`
- `schema_version`: `v1`
- `timezone_policy`: `utc_required`
- `required_fields`: `[event_time_utc, source_id, site_id, house_id, temp_c, humidity_percent, co2_ppm]`

### Mapping телеметрии

| source_field | target_field | target_entity | unit_in | unit_out | transform | required | quality_rule |
| --- | --- | --- | --- | --- | --- | --- | --- |
| `timestamp` | `timestamp` | `barn_climate_profile` | `RFC3339` | `RFC3339` | `to_utc()` | `true` | `valid_rfc3339` |
| `house` | `house_id` | `barn_climate_profile` | `string` | `string` | `trim()` | `true` | `non_empty` |
| `temp` | `temp_c` | `barn_climate_profile` | `C` | `C` | `round(1)` | `true` | `-20..50` |
| `rh` | `humidity_percent` | `barn_climate_profile` | `%` | `%` | `round(1)` | `true` | `0..100` |
| `co2` | `co2_ppm` | `barn_climate_profile` | `ppm` | `ppm` | `round(0)` | `true` | `0..10000` |
| `nh3` | `nh3_ppm` | `barn_climate_profile` | `ppm` | `ppm` | `round(1)` | `false` | `0..200` |

### Надежность и fallback

- `idempotency_key`: `[source_id, event_time_utc, house_id]`
- `ordering_policy`: `event_time_utc` (окно переупорядочивания `120s`)
- `retry_policy`: `max_retries=5`, `backoff_ms=750`
- `fallback_source`: `swine-local-sensor-gateway-v1`
- `anomaly_policy`: при расхождении `temp_c` primary/fallback > `2.0C` -> `quality=warn`
- `freshness_sla`: `60s`

### Безопасность

- `auth_method`: `token`
- `secret_ref`: `vault/swine/climatepro/mqtt-token`
- `allowed_endpoints/topics`: `["swine/+/climate/telemetry"]`
- `audit_required`: `true`

## 2. Профиль B: feed/water counters gateway

- `adapter_profile_id`: `swine-feedwater-gateway-v1`
- `industry_code`: `swine`
- `module_id`: `industry.swine.water`
- `source_type`: `gateway`
- `version`: `1.0.0`
- `status`: `draft`
- `protocol`: `http`
- `payload_format`: `json`
- `schema_version`: `v1`
- `timezone_policy`: `utc_required`
- `required_fields`: `[event_time_utc, source_id, site_id, house_id, feed_gram_per_head, water_l_per_head]`

### Mapping телеметрии

| source_field | target_field | target_entity | unit_in | unit_out | transform | required | quality_rule |
| --- | --- | --- | --- | --- | --- | --- | --- |
| `event_time_utc` | `timestamp` | `water_consumption_snapshot` | `RFC3339` | `RFC3339` | `to_utc()` | `true` | `valid_rfc3339` |
| `feed_gram_per_head` | `feed_gram_per_head_day` | `feeding_plan_snapshot` | `g/head/day` | `g/head/day` | `round(2)` | `true` | `0..5000` |
| `water_l_per_head` | `water_l_per_head_day` | `water_consumption_snapshot` | `L/head/day` | `L/head/day` | `round(2)` | `true` | `0..100` |
| `pressure_kpa` | `water_line_pressure_kpa` | `water_consumption_snapshot` | `kPa` | `kPa` | `round(2)` | `false` | `0..1000` |

### Надежность и fallback

- `idempotency_key`: `[source_id, event_time_utc, house_id]`
- `ordering_policy`: `event_time_utc`
- `retry_policy`: `max_retries=3`, `backoff_ms=500`
- `fallback_source`: `manual-shift-input`
- `anomaly_policy`: сравнение gateway vs manual (`abs(deviation_pct) > 5` -> `warn`)
- `freshness_sla`: `5m`

### Безопасность

- `auth_method`: `mTLS`
- `secret_ref`: `vault/swine/feedwater/client-cert`
- `allowed_endpoints/topics`: `["POST /api/v1/swine-water/commands/ingest","POST /api/v1/swine-feeding/commands/ingest"]`
- `audit_required`: `true`

## 3. Профиль C: biosecurity events service

- `adapter_profile_id`: `swine-biosecurity-service-v1`
- `industry_code`: `swine`
- `module_id`: `industry.swine.biosecurity`
- `source_type`: `external_service`
- `version`: `1.0.0`
- `status`: `draft`
- `protocol`: `http`
- `payload_format`: `json`
- `schema_version`: `v1`
- `timezone_policy`: `utc_required`
- `required_fields`: `[event_time_utc, source_id, site_id, zone_id, event_code, severity]`

### Mapping телеметрии

| source_field | target_field | target_entity | unit_in | unit_out | transform | required | quality_rule |
| --- | --- | --- | --- | --- | --- | --- | --- |
| `event_time_utc` | `event_time` | `biosecurity_event` | `RFC3339` | `RFC3339` | `to_utc()` | `true` | `valid_rfc3339` |
| `event_code` | `event_code` | `biosecurity_event` | `string` | `string` | `lowercase()` | `true` | `enum_whitelist` |
| `severity` | `severity` | `biosecurity_event` | `string` | `string` | `normalize_severity()` | `true` | `critical|high|medium|low|info` |
| `comment` | `payload.comment` | `biosecurity_event` | `string` | `string` | `trim()` | `false` | `max_len_1024` |

### Надежность и fallback

- `idempotency_key`: `[source_id, event_time_utc, event_code, zone_id]`
- `ordering_policy`: `event_time_utc`
- `retry_policy`: `max_retries=4`, `backoff_ms=1000`
- `fallback_source`: `swine-manual-biosecurity-form`
- `anomaly_policy`: повтор одинакового `event_code` > `N=5` за `10m` -> `possible_loop`
- `freshness_sla`: `2m`

### Безопасность

- `auth_method`: `token`
- `secret_ref`: `vault/swine/biosecurity/api-token`
- `allowed_endpoints/topics`: `["POST /api/v1/swine-biosecurity/commands/ingest"]`
- `audit_required`: `true`
