{
  "openapi": "3.1.0",
  "info": {
    "title": "MacEkran Genel API",
    "version": "1.0.0",
    "description": "Türkiye spor TV yayın rehberi verisine açık, anahtarsız REST erişimi. Maçların hangi kanalda yayınlandığı, takım/lig/kanal varlıkları ve arama. Adil kullanım politikası geçerlidir; yüksek hacim için iletisim@macekran.com.",
    "license": {
      "name": "CC BY 4.0",
      "url": "https://creativecommons.org/licenses/by/4.0/"
    },
    "contact": {
      "name": "MacEkran",
      "email": "iletisim@macekran.com",
      "url": "https://macekran.com"
    }
  },
  "servers": [
    {
      "url": "https://macekran.com/api/v1",
      "description": "Üretim"
    }
  ],
  "tags": [
    {
      "name": "matches",
      "description": "Maçlar ve yayın bilgileri"
    },
    {
      "name": "teams",
      "description": "Takımlar"
    },
    {
      "name": "leagues",
      "description": "Ligler / turnuvalar"
    },
    {
      "name": "channels",
      "description": "Yayıncı kanallar"
    },
    {
      "name": "search",
      "description": "Arama"
    }
  ],
  "paths": {
    "/matches": {
      "get": {
        "tags": [
          "matches"
        ],
        "summary": "Tarihe göre maçlar",
        "description": "Verilen İstanbul günündeki maçları döner. `sport`/`league` slug ile filtrelenir.",
        "parameters": [
          {
            "name": "date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "example": "2026-06-22",
            "description": "YYYY-MM-DD (Europe/Istanbul)"
          },
          {
            "name": "sport",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "futbol"
          },
          {
            "name": "league",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "super-lig"
          }
        ],
        "responses": {
          "200": {
            "description": "Maç listesi",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Match"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/matches/{id}": {
      "get": {
        "tags": [
          "matches"
        ],
        "summary": "Maç detayı",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 1234
          }
        ],
        "responses": {
          "200": {
            "description": "Maç",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Match"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/teams/{slug}": {
      "get": {
        "tags": [
          "teams"
        ],
        "summary": "Takım bilgisi",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "fenerbahce"
          }
        ],
        "responses": {
          "200": {
            "description": "Takım",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Team"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/teams/{slug}/matches": {
      "get": {
        "tags": [
          "teams"
        ],
        "summary": "Takımın maçları (yaklaşan + son)",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "galatasaray"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Yaklaşan ve son maçlar",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "upcoming": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Match"
                      }
                    },
                    "recent": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Match"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/leagues/{slug}": {
      "get": {
        "tags": [
          "leagues"
        ],
        "summary": "Lig bilgisi",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "super-lig"
          }
        ],
        "responses": {
          "200": {
            "description": "Lig",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/League"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/leagues/{slug}/matches": {
      "get": {
        "tags": [
          "leagues"
        ],
        "summary": "Ligin maçları",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "champions-league"
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Maç listesi",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Match"
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/channels/{slug}": {
      "get": {
        "tags": [
          "channels"
        ],
        "summary": "Kanal bilgisi",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "bein-sports-1"
          }
        ],
        "responses": {
          "200": {
            "description": "Kanal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Channel"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/channels/{slug}/matches": {
      "get": {
        "tags": [
          "channels"
        ],
        "summary": "Kanalın bugünkü yayınları",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "bein-sports-1"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Maç listesi",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Match"
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/search": {
      "get": {
        "tags": [
          "search"
        ],
        "summary": "Takım, lig, kanal, oyuncu ve maç araması",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 120
            },
            "example": "fener"
          },
          {
            "name": "sport",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Gruplanmış arama sonuçları",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "teams": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Team"
                      }
                    },
                    "leagues": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/League"
                      }
                    },
                    "channels": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Channel"
                      }
                    },
                    "players": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "matches": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Match"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Hata",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "message"
        ],
        "example": {
          "error": "not_found",
          "message": "Team 'xyz' bulunamadı"
        }
      },
      "Sport": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "icon": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Team": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "shortName": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          },
          "logoUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "color": {
            "type": [
              "string",
              "null"
            ]
          },
          "secondaryColor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "League": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "displayName": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          },
          "season": {
            "type": [
              "string",
              "null"
            ]
          },
          "logoUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "color": {
            "type": [
              "string",
              "null"
            ]
          },
          "priority": {
            "type": [
              "integer",
              "null"
            ]
          },
          "sport": {
            "$ref": "#/components/schemas/Sport"
          }
        }
      },
      "Channel": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "shortName": {
            "type": [
              "string",
              "null"
            ]
          },
          "initials": {
            "type": [
              "string",
              "null"
            ]
          },
          "logoUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "streamUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "brandColor": {
            "type": [
              "string",
              "null"
            ]
          },
          "parentBrand": {
            "type": [
              "string",
              "null"
            ]
          },
          "tier": {
            "type": [
              "string",
              "null"
            ]
          },
          "platform": {
            "type": [
              "string",
              "null"
            ]
          },
          "monthlyPrice": {
            "type": [
              "string",
              "null"
            ]
          },
          "affiliateUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          }
        }
      },
      "Broadcast": {
        "type": "object",
        "properties": {
          "channel": {
            "$ref": "#/components/schemas/Channel"
          },
          "country": {
            "type": "string",
            "example": "TR"
          },
          "verifiedBy": {
            "type": "string",
            "enum": [
              "api",
              "scraper",
              "manual"
            ]
          },
          "verifiedAt": {
            "type": "string",
            "format": "date-time"
          },
          "sourceUrl": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Match": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": [
              "string",
              "null"
            ]
          },
          "kickoffAt": {
            "type": "string",
            "format": "date-time"
          },
          "venue": {
            "type": [
              "string",
              "null"
            ]
          },
          "referee": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "live",
              "finished",
              "postponed",
              "cancelled"
            ]
          },
          "week": {
            "type": [
              "integer",
              "null"
            ]
          },
          "homeScore": {
            "type": [
              "integer",
              "null"
            ]
          },
          "awayScore": {
            "type": [
              "integer",
              "null"
            ]
          },
          "minute": {
            "type": [
              "integer",
              "null"
            ]
          },
          "home": {
            "$ref": "#/components/schemas/Team"
          },
          "away": {
            "$ref": "#/components/schemas/Team"
          },
          "league": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/League"
              },
              {
                "type": "null"
              }
            ]
          },
          "sport": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Sport"
              },
              {
                "type": "null"
              }
            ]
          },
          "broadcasts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Broadcast"
            }
          }
        }
      }
    }
  }
}