openapi: 3.0.0
info:
  title: Tanzania Universities API
  description: |-
    Comprehensive REST API for Tanzanian higher education institutions data.
    Features JWT authentication, caching, and full CRUD operations.
  version: 1.0.0
  contact:
    name: API Support
    email: support@tanzania-universities-api.com
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT

servers:
  - url: http://localhost:3000/api/v1
    description: Development server

tags:
  - name: Authentication
    description: User login operations
  - name: Universities
    description: Tanzanian university data operations

paths:
  /login:
    post:
      tags: [Authentication]
      summary: Authenticate user
      description: Returns JWT token for API access
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                  example: admin
                password:
                  type: string
                  example: password
      responses:
        '200':
          description: Authentication successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: string
                    example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
        '401':
          description: Invalid credentials

  /universities:
    get:
      tags: [Universities]
      summary: List all universities
      description: Returns paginated list of Tanzanian universities
      parameters:
        - $ref: '#/components/parameters/limitParam'
        - $ref: '#/components/parameters/offsetParam'
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UniversityListResponse'
    post:
      tags: [Universities]
      summary: Create new university
      description: Admin-only endpoint to add new university
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UniversityInput'
      responses:
        '201':
          description: University created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/University'

  /universities/by-location:
    get:
      tags: [Universities]
      summary: Filter by location
      description: Returns universities in specified location
      parameters:
        - name: location
          in: query
          required: true
          schema:
            type: string
          example: "Dar es Salaam"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UniversityListResponse'

components:
  schemas:
    University:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: "5f8d0d55b54764421b7156c3"
        name:
          type: string
          example: "University of Dar es Salaam"
        location:
          type: string
          example: "Dar es Salaam"
        courses:
          type: array
          items:
            type: string
          example: ["Medicine", "Engineering", "Law"]
        established:
          type: integer
          example: 1961
        website:
          type: string
          format: url
          example: "https://www.udsm.ac.tz"
    
    UniversityInput:
      type: object
      required:
        - name
        - location
      properties:
        name:
          type: string
        location:
          type: string
        courses:
          type: array
          items:
            type: string
        established:
          type: integer
        website:
          type: string
          format: url
    
    UniversityListResponse:
      type: object
      properties:
        status:
          type: string
          example: "success"
        data:
          type: array
          items:
            $ref: '#/components/schemas/University'
        pagination:
          type: object
          properties:
            total:
              type: integer
            limit:
              type: integer
            offset:
              type: integer

  parameters:
    limitParam:
      name: limit
      in: query
      description: Number of items to return
      required: false
      schema:
        type: integer
        default: 10
    offsetParam:
      name: offset
      in: query
      description: Number of items to skip
      required: false
      schema:
        type: integer
        default: 0

  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT