{"openapi":"3.0.3","info":{"title":"amt-b2b ↔ allmytour Integration API","version":"1.0.0","description":"올마이투어 (allmytour) 시스템이 amt-b2b 와 통합하기 위한 양방향 REST API.\n\n### 통합 방향\n- **Inbound (allmytour → amt-b2b)**: 상품/객실/요금제/가격/재고 push sync\n- **Outbound (amt-b2b → allmytour)**: 예약/취소 push (별도 명세, 그쪽 endpoint\n  에서 정의)\n\n### 인증 (Inbound)\n모든 mutation endpoint 는 HMAC-SHA256 서명 검증 필수:\n\n- 헤더 `X-Allmytour-Signature: sha256=<64-hex>`\n  → `HMAC-SHA256(body, ALLMYTOUR_INBOUND_SECRET)` hex\n- 헤더 `X-Allmytour-Event-Id: <UUID>` — 멱등성 dedup key\n- `Content-Type: application/json`\n\n`GET /health` 는 인증 없음 (연결 확인).\n\n### 멱등성 (Idempotency)\n- body 의 SHA-256 해시로 dedup. 동일 payload 가 이미 `applied` 상태로\n  처리되었으면 `{ ok: true, duplicate: true }` 응답 (DB 변경 없음).\n- `X-Allmytour-Event-Id` 는 외부 추적용 key (충돌해도 무관).\n\n### Push 순서 강제\n부모-자식 매핑 가드로 다음 순서 필수:\n\n1. `POST /properties` — 숙소 먼저\n2. `POST /rooms`      — 객실 (property_idx 매핑)\n3. `POST /rateplans`  — 요금제 (room_idx 매핑) → products 자동 생성\n4. `POST /prices`     — 가격 (rateplan_idx 매핑)\n5. `POST /inventory`  — 재고 (room_idx 매핑)\n\n부모가 없으면 `PARENT_*_NOT_FOUND` 에러.\n\n### 배치 크기\n- 한 요청당 `items[]` 최대 1000 row. 초과 시 `BATCH_TOO_LARGE`.\n\n### 에러 포맷\n`{ \"error\": { \"code\": \"VALIDATION_FAILED\", \"message\": \"...\" } }`\n\n### 가격 용어 매핑 (참고)\n| allmytour | amt-b2b | 의미 |\n|---|---|---|\n| `price` | `selling_price` | 고객 결제가 |\n| `net_price` | `purchase_price` | 매입가 |\n| `due_price` | `net_rate` | 입금가 (파트너 정산) |\n","contact":{"name":"amt-b2b operations","email":"ops@allmytour.com"},"license":{"name":"Proprietary"}},"servers":[{"url":"https://api.amt-b2b.example.com","description":"production"},{"url":"https://staging.amt-b2b.example.com","description":"staging"},{"url":"http://localhost:4000","description":"local dev"}],"components":{"securitySchemes":{"AllmytourHmac":{"type":"apiKey","in":"header","name":"X-Allmytour-Signature","description":"HMAC-SHA256 hex 서명. `sha256=<64-hex>` 형식.\n예: `sha256=3f8a9c2d1e4b7f6a5c8e9d2b1a4f7e6c3b8a9d2e1c4f7b6a5e8c9d2b1a4f7e6c`\n\n검증 secret 은 운영팀이 별도 보안 채널 (Vault / 1Password) 로 공유.\nNode.js sample:\n```js\nconst crypto = require('crypto');\nconst sig = 'sha256=' + crypto.createHmac('sha256', SECRET)\n  .update(rawBody).digest('hex');\n```\n"}},"parameters":{"EventIdHeader":{"name":"X-Allmytour-Event-Id","in":"header","required":true,"schema":{"type":"string","format":"uuid","example":"550e8400-e29b-41d4-a716-446655440000"},"description":"외부 추적용 unique event ID. dedup 은 body hash 기준."}},"schemas":{"UpsertResponse":{"type":"object","required":["ok","applied","skipped","errors","event_id","payload_hash"],"properties":{"ok":{"type":"boolean","example":true},"applied":{"type":"integer","description":"실제 upsert 된 row 수","example":42},"skipped":{"type":"integer","description":"dedup 또는 변경 없음으로 skip","example":8},"duplicate":{"type":"boolean","description":"같은 payload_hash 가 이미 applied 상태였을 때만 true","example":false},"errors":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer","description":"items[] index"},"code":{"type":"string","example":"FIELD_REQUIRED"},"message":{"type":"string"}}}},"event_id":{"type":"string","format":"uuid"},"payload_hash":{"type":"string","description":"SHA-256 hex of body","example":"abc123..."}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","example":"SIGNATURE_INVALID"},"message":{"type":"string","example":"HMAC signature mismatch."}}}}},"PropertyItem":{"type":"object","required":["idx","name_kr","country_code"],"properties":{"idx":{"type":"integer","format":"int64","description":"allmytour product.idx (BIGINT). 매핑 자연키.","example":12345},"name_kr":{"type":"string","example":"서울 호텔 센트럴"},"name_en":{"type":"string","example":"Hotel Seoul Central"},"name_zh":{"type":"string","example":"首尔中心酒店"},"country_code":{"type":"string","minLength":2,"maxLength":2,"description":"ISO 3166-1 alpha-2 (대문자 자동 변환)","example":"KR"},"city":{"type":"string","example":"Seoul"},"city_code":{"type":"string","example":"seoul","description":"lowercase slug"},"star_rating":{"type":"number","format":"float","minimum":0,"maximum":5,"example":4.5},"property_type":{"type":"string","enum":["hotel","resort","motel","villa","hostel","apartment"],"default":"hotel"},"status":{"type":"string","enum":["draft","review","active","paused","archived"],"default":"active"},"overview":{"type":"string"},"checkin_time":{"type":"string","example":"15:00"},"checkout_time":{"type":"string","example":"11:00"},"avail":{"type":"boolean","description":"false 시 status=paused 강제","default":true}}},"PropertyUpsertRequest":{"type":"object","required":["items"],"properties":{"items":{"type":"array","minItems":1,"maxItems":1000,"items":{"$ref":"#/components/schemas/PropertyItem"}}}},"RoomItem":{"type":"object","required":["idx","product_idx","name"],"properties":{"idx":{"type":"integer","format":"int64","example":67890},"product_idx":{"type":"integer","format":"int64","description":"parent property idx","example":12345},"name":{"type":"string","example":"Deluxe Twin"},"basic_num":{"type":"integer","minimum":1,"example":2},"max_num":{"type":"integer","minimum":1,"example":4},"adt_max_num":{"type":"integer","minimum":1,"example":3},"chd_max_num":{"type":"integer","minimum":0,"example":2},"hardblock_flag":{"type":"boolean","description":"true=hard_block, false=soft_block","default":false},"roomtype_name":{"type":"string","example":"Twin Room"}}},"RoomUpsertRequest":{"type":"object","required":["items"],"properties":{"items":{"type":"array","minItems":1,"maxItems":1000,"items":{"$ref":"#/components/schemas/RoomItem"}}}},"RatePlanItem":{"type":"object","required":["idx","room_idx","name"],"properties":{"idx":{"type":"integer","format":"int64","example":11111},"room_idx":{"type":"integer","format":"int64","description":"parent room idx","example":67890},"product_idx":{"type":"integer","format":"int64","description":"parent property idx (비정규화 보조)","example":12345},"name":{"type":"string","example":"Room Only — Standard"},"rateplan_type":{"type":"string","enum":["A","V","VB"],"description":"A=기간별, V=바우처, VB=바우처B. 우리는 V/VB → fixed, A → standard 매핑.","example":"A"},"meal_plan":{"type":"string","example":"room_only"},"min_los":{"type":"integer","minimum":1,"example":1},"max_los":{"type":"integer","minimum":1,"example":30},"sale_start_date":{"type":"string","format":"date"},"sale_end_date":{"type":"string","format":"date"},"stay_start_date":{"type":"string","format":"date"},"stay_end_date":{"type":"string","format":"date"},"cancel_date":{"type":"string","description":"TIME 또는 timestamptz"},"avail":{"type":"boolean","default":true}}},"RatePlanUpsertRequest":{"type":"object","required":["items"],"properties":{"items":{"type":"array","minItems":1,"maxItems":1000,"items":{"$ref":"#/components/schemas/RatePlanItem"}}}},"PriceItem":{"type":"object","required":["rateplan_idx","date","price"],"properties":{"rateplan_idx":{"type":"integer","format":"int64","example":11111},"date":{"type":"string","format":"date","example":"2026-06-01"},"price":{"type":"number","description":"판매가 → selling_price","example":138000},"net_price":{"type":"number","description":"공급가/매입가 → purchase_price","example":120000},"due_price":{"type":"number","description":"입금가/파트너 정산가 → net_rate","example":115000},"normal_price":{"type":"number","description":"정상가 (할인 전, 우리 schema 에 없음)","example":150000},"currency":{"type":"string","minLength":3,"maxLength":3,"default":"KRW","example":"KRW"}}},"PriceUpsertRequest":{"type":"object","required":["items"],"properties":{"items":{"type":"array","minItems":1,"maxItems":1000,"items":{"$ref":"#/components/schemas/PriceItem"}}}},"InventoryItem":{"type":"object","required":["room_idx","date","stock"],"properties":{"room_idx":{"type":"integer","format":"int64","example":67890},"date":{"type":"string","format":"date","example":"2026-06-01"},"stock":{"type":"integer","minimum":0,"description":"현재 잔여 재고","example":3},"base_stock":{"type":"integer","minimum":0,"description":"원래 배정 재고. 미지정 시 stock 과 동일.","example":5},"hardblock_flag":{"type":"boolean","description":"true=hard_block, false=soft_block. inventory_calendar.inventory_type 에 매핑","default":false}}},"InventoryUpsertRequest":{"type":"object","required":["items"],"properties":{"items":{"type":"array","minItems":1,"maxItems":1000,"items":{"$ref":"#/components/schemas/InventoryItem"}}}}}},"paths":{"/api/integrations/allmytour/health":{"get":{"summary":"연결 확인 (인증 X)","description":"통합 전 endpoint 도달 여부 확인. 실 데이터 처리 없음.","tags":["Health"],"security":[],"responses":{"200":{"description":"정상","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","example":true},"service":{"type":"string","example":"allmytour-integration"},"version":{"type":"string","example":"1.0"},"timestamp":{"type":"string","format":"date-time"}}}}}}}}},"/api/integrations/allmytour/properties":{"post":{"summary":"숙소 (property) 배치 upsert","description":"allmytour `product` row 를 amt-b2b `properties` 로 upsert. 매핑 키:\n`(external_source='allmytour', external_idx=item.idx)`.\n\nsupply_method 는 항상 `allmytour_api` 로 강제 (예약 saga 가 올바른\nadapter dispatch).\n","tags":["Sync — Inventory Tree"],"security":[{"AllmytourHmac":[]}],"parameters":[{"$ref":"#/components/parameters/EventIdHeader"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PropertyUpsertRequest"},"example":{"items":[{"idx":12345,"name_kr":"서울 호텔 센트럴","name_en":"Hotel Seoul Central","country_code":"KR","city":"Seoul","city_code":"seoul","star_rating":4.5,"property_type":"hotel","status":"active","checkin_time":"15:00","checkout_time":"11:00","avail":true}]}}}},"responses":{"200":{"description":"처리 결과","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpsertResponse"}}}},"400":{"description":"payload 검증 실패","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"HMAC 서명 누락/무효","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"서버 에러","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/integrations/allmytour/rooms":{"post":{"summary":"객실 (room_type) 배치 upsert","description":"allmytour `product_room` 매핑. 부모 `properties.external_idx`\n(item.product_idx) 가 먼저 push 되어 있어야 함.\n\n매핑 키: `(external_source='allmytour', external_idx=item.idx)`.\n","tags":["Sync — Inventory Tree"],"security":[{"AllmytourHmac":[]}],"parameters":[{"$ref":"#/components/parameters/EventIdHeader"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RoomUpsertRequest"},"example":{"items":[{"idx":67890,"product_idx":12345,"name":"Deluxe Twin","basic_num":2,"max_num":4,"adt_max_num":3,"chd_max_num":2,"hardblock_flag":false}]}}}},"responses":{"200":{"description":"처리 결과","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpsertResponse"}}}},"400":{"description":"검증 실패 또는 PARENT_PROPERTY_NOT_FOUND","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"HMAC 무효","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"서버 에러","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/integrations/allmytour/rateplans":{"post":{"summary":"요금제 (rate_plan) 배치 upsert + products 자동 생성","description":"allmytour `product_rateplan` 매핑. 부모 `room_types_b2b.external_idx`\n(item.room_idx) 가 먼저 push 되어 있어야 함.\n\n`(property_id, room_type_id, rate_plan_id)` 조합으로 `products` 도 자동\n생성 (ON CONFLICT DO NOTHING). 이후 prices / inventory upsert 가\nrateplan_idx 또는 room_idx 로 동작.\n","tags":["Sync — Inventory Tree"],"security":[{"AllmytourHmac":[]}],"parameters":[{"$ref":"#/components/parameters/EventIdHeader"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RatePlanUpsertRequest"},"example":{"items":[{"idx":11111,"room_idx":67890,"product_idx":12345,"name":"Room Only — Standard","rateplan_type":"A","meal_plan":"room_only","min_los":1,"max_los":30,"sale_start_date":"2026-01-01","sale_end_date":"2026-12-31","avail":true}]}}}},"responses":{"200":{"description":"처리 결과","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpsertResponse"}}}},"400":{"description":"검증 실패 또는 PARENT_ROOM_NOT_FOUND","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"HMAC 무효","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"서버 에러","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/integrations/allmytour/prices":{"post":{"summary":"날짜별 가격 배치 upsert","description":"allmytour `product_rateplan_price` 매핑. 부모 `rate_plans.external_idx`\n(item.rateplan_idx) 가 먼저 push 되어 있어야 함.\n\n가격 용어 매핑:\n- `price` → `selling_price` (고객 결제가)\n- `net_price` → `purchase_price` (매입가)\n- `due_price` → `net_rate` (입금가)\n\nUNIQUE `(product_id, stay_date)` 기준 ON CONFLICT DO UPDATE.\n","tags":["Sync — Pricing & Stock"],"security":[{"AllmytourHmac":[]}],"parameters":[{"$ref":"#/components/parameters/EventIdHeader"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PriceUpsertRequest"},"example":{"items":[{"rateplan_idx":11111,"date":"2026-06-01","price":138000,"net_price":120000,"due_price":115000,"currency":"KRW"},{"rateplan_idx":11111,"date":"2026-06-02","price":142000,"net_price":124000,"due_price":118000,"currency":"KRW"}]}}}},"responses":{"200":{"description":"처리 결과","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpsertResponse"}}}},"400":{"description":"검증 실패 또는 PARENT_RATEPLAN_NOT_FOUND","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"HMAC 무효","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"서버 에러","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/integrations/allmytour/inventory":{"post":{"summary":"날짜별 재고 배치 upsert","description":"allmytour `product_room_stock` 매핑. 부모 `room_types_b2b.external_idx`\n(item.room_idx) 가 먼저 push 되어 있어야 하며, 해당 room 의 products\n가 적어도 1개 있어야 함 (rateplan upsert 시 자동 생성됨).\n\n같은 room 의 모든 products 에 동일 stock 동기화 (1 room → N products).\n\n매핑:\n- `allotment` = `base_stock` (또는 stock if base_stock 미지정)\n- `sold` = `base_stock - stock` (이미 차감된 양)\n- `inventory_type` = `hardblock_flag ? 'hard_block' : 'soft_block'`\n","tags":["Sync — Pricing & Stock"],"security":[{"AllmytourHmac":[]}],"parameters":[{"$ref":"#/components/parameters/EventIdHeader"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InventoryUpsertRequest"},"example":{"items":[{"room_idx":67890,"date":"2026-06-01","stock":3,"base_stock":5,"hardblock_flag":false}]}}}},"responses":{"200":{"description":"처리 결과","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpsertResponse"}}}},"400":{"description":"검증 실패 또는 PARENT_ROOM_PRODUCTS_NOT_FOUND","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"HMAC 무효","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"서버 에러","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}},"tags":[{"name":"Health","description":"인증 없는 헬스 체크"},{"name":"Sync — Inventory Tree","description":"상품 / 객실 / 요금제 (계층 구조)"},{"name":"Sync — Pricing & Stock","description":"날짜별 가격 / 재고"}]}