{
    "openapi": "3.0.3",
    "info": {
        "title": "AMOTORS RADAR - Market Data API",
        "version": "1.0.0",
        "description": "נתוני שוק רכב מיד2 לסוכנויות. אותו מפתח רישיון של התוסף. תיעוד מלא: https://amotors.co.il/docs",
        "contact": {
            "email": "licence@amotors.co.il",
            "url": "https://amotors.co.il/contact"
        }
    },
    "servers": [
        {
            "url": "https://api.amotors.co.il/api/v1/yad2"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "מפתח הרישיון שקיבלתם. אל תשלחו X-Device-Id - היא שייכת לתוסף."
            }
        },
        "responses": {
            "Unauthorized": {
                "description": "מפתח חסר, שגוי או פג",
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "object",
                            "properties": {
                                "message": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            },
            "RateLimited": {
                "description": "חריגת קצב (429)"
            }
        },
        "schemas": {
            "Snapshot": {
                "type": "object",
                "properties": {
                    "captured_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "manufacturer_id": {
                        "type": "string"
                    },
                    "model_id": {
                        "type": "string"
                    },
                    "total": {
                        "type": "integer"
                    },
                    "scanned": {
                        "type": "integer"
                    },
                    "priced": {
                        "type": "integer"
                    },
                    "avg_price": {
                        "type": "integer"
                    },
                    "med_price": {
                        "type": "integer"
                    },
                    "min_price": {
                        "type": "integer"
                    },
                    "max_price": {
                        "type": "integer"
                    },
                    "avg_hand": {
                        "type": "number"
                    },
                    "avg_days": {
                        "type": "integer"
                    },
                    "dropped_count": {
                        "type": "integer"
                    },
                    "dropped_avg_pct": {
                        "type": "integer"
                    },
                    "trims": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "k": {
                                    "type": "string"
                                },
                                "count": {
                                    "type": "integer"
                                },
                                "avg": {
                                    "type": "integer"
                                },
                                "med": {
                                    "type": "integer"
                                }
                            }
                        }
                    },
                    "items": {
                        "type": "array",
                        "description": "רק עם with_items=1",
                        "items": {
                            "$ref": "#/components/schemas/Listing"
                        }
                    }
                }
            },
            "Listing": {
                "type": "object",
                "properties": {
                    "token": {
                        "type": "string"
                    },
                    "price": {
                        "type": "integer",
                        "nullable": true
                    },
                    "prevPrice": {
                        "type": "integer",
                        "nullable": true
                    },
                    "dropPct": {
                        "type": "integer",
                        "nullable": true
                    },
                    "hand": {
                        "type": "integer",
                        "nullable": true
                    },
                    "year": {
                        "type": "integer",
                        "nullable": true
                    },
                    "trim": {
                        "type": "string",
                        "nullable": true
                    },
                    "daysListed": {
                        "type": "integer",
                        "nullable": true
                    },
                    "stale": {
                        "type": "boolean"
                    },
                    "dealScore": {
                        "type": "string",
                        "enum": [
                            "hot",
                            "good",
                            "mid",
                            "cold"
                        ],
                        "nullable": true
                    },
                    "ours": {
                        "type": "boolean"
                    },
                    "url": {
                        "type": "string"
                    }
                }
            }
        }
    },
    "paths": {
        "/../sync/market": {
            "get": {
                "summary": "Sync API: תמונת השוק העדכנית של פלח מכל הרשת (תוסף בתשלום)",
                "description": "הצילום הטרי ביותר מכל משתמשי הרשת: מדדים, פילוח גימורים, עקומת מחיר-זמן. כתובת מלאה: https://api.amotors.co.il/api/v1/sync/market. דורש sync_enabled על הרישיון (403 בלעדיו).",
                "parameters": [
                    {
                        "name": "manufacturer",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "model",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "year",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "include",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "items"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "תמונת שוק + עקומה"
                    },
                    "403": {
                        "description": "sync_not_enabled"
                    },
                    "404": {
                        "description": "segment_not_found"
                    }
                }
            }
        },
        "/../sync/estimate": {
            "get": {
                "summary": "Sync API: צפי ימים-למכירה למחיר נתון (תוסף בתשלום)",
                "description": "אינטרפולציה על עקומת מחיר-זמן של הרשת. כתובת מלאה: https://api.amotors.co.il/api/v1/sync/estimate.",
                "parameters": [
                    {
                        "name": "manufacturer",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "model",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "year",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "price",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "number"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "diff_pct + expected_days"
                    },
                    "403": {
                        "description": "sync_not_enabled"
                    },
                    "404": {
                        "description": "no_curve"
                    }
                }
            }
        },
        "/../sync/trend": {
            "get": {
                "summary": "Sync API: היסטוריית חציון/היצע של פלח עד 180 יום (תוסף בתשלום)",
                "description": "כתובת מלאה: https://api.amotors.co.il/api/v1/sync/trend.",
                "parameters": [
                    {
                        "name": "manufacturer",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "model",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "year",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "נקודות + כיוון + עקומה"
                    },
                    "403": {
                        "description": "sync_not_enabled"
                    }
                }
            }
        },
        "/market-data/latest": {
            "get": {
                "summary": "סריקות שוק אחרונות לפי דגם",
                "description": "ה-endpoint המרכזי. חציון, ממוצע, פירוק גימורים וכל המודעות.",
                "parameters": [
                    {
                        "name": "manufacturer",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "מזהה יצרן יד2"
                    },
                    {
                        "name": "model",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "מזהה דגם יד2"
                    },
                    {
                        "name": "filter_url",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "לחלופין: כתובת סינון יד2"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "maximum": 50,
                            "default": 10
                        }
                    },
                    {
                        "name": "with_items",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "enum": [
                                0,
                                1
                            ]
                        },
                        "description": "לכלול את רשימת המודעות"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "הצלחה",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "ok": {
                                            "type": "boolean"
                                        },
                                        "agency": {
                                            "type": "string"
                                        },
                                        "snapshots": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Snapshot"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "429": {
                        "$ref": "#/components/responses/RateLimited"
                    }
                }
            }
        },
        "/listing/{token}": {
            "get": {
                "summary": "מצב מודעה בודדת",
                "description": "המחיר האחרון והאם עוד באוויר. מזין את תג \"מפורסם ביד2\".",
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "הצלחה",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "ok": {
                                            "type": "boolean"
                                        },
                                        "found": {
                                            "type": "boolean"
                                        },
                                        "token": {
                                            "type": "string"
                                        },
                                        "price": {
                                            "type": "integer",
                                            "nullable": true
                                        },
                                        "live": {
                                            "type": "boolean"
                                        },
                                        "trim": {
                                            "type": "string",
                                            "nullable": true
                                        },
                                        "seenAt": {
                                            "type": "string",
                                            "format": "date-time"
                                        },
                                        "url": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    }
                }
            }
        },
        "/match": {
            "get": {
                "summary": "שידוך מודעה לרכב מהמלאי",
                "description": "מחזיר את המודעה שלכם הקרובה ביותר במחיר.",
                "parameters": [
                    {
                        "name": "manufacturer",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "model",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "trim",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "year",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "price",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "הצלחה",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "ok": {
                                            "type": "boolean"
                                        },
                                        "suggestion": {
                                            "type": "object",
                                            "properties": {
                                                "token": {
                                                    "type": "string"
                                                },
                                                "price": {
                                                    "type": "integer",
                                                    "nullable": true
                                                },
                                                "diffPct": {
                                                    "type": "integer",
                                                    "nullable": true
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    }
                }
            }
        },
        "/catalog": {
            "get": {
                "summary": "קטלוג יצרנים ודגמים",
                "description": "מיפוי יצרן←דגמים עם מזהי יד2. כמעט סטטי, תומך ETag.",
                "responses": {
                    "200": {
                        "description": "הצלחה"
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    }
                }
            }
        },
        "/license": {
            "get": {
                "summary": "מצב הרישיון",
                "description": "להצגת \"מנוי פעיל עד...\" ולזיהוי מוקדם של תפוגה.",
                "responses": {
                    "200": {
                        "description": "הצלחה",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "ok": {
                                            "type": "boolean"
                                        },
                                        "plan": {
                                            "type": "string"
                                        },
                                        "capped": {
                                            "type": "boolean"
                                        },
                                        "expires_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "nullable": true
                                        },
                                        "days_left": {
                                            "type": "integer",
                                            "nullable": true
                                        },
                                        "reason": {
                                            "type": "string",
                                            "nullable": true,
                                            "enum": [
                                                "expired",
                                                "revoked",
                                                "device_mismatch",
                                                "invalid",
                                                "no_token"
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}