openapi: 3.0.3
info:
  title: Japregeo API
  description: Backend API untuk aplikasi Japregeo
  version: 1.0.0
  contact:
    name: Japregeo Team
    email: support@japregeo.com

servers:
  - url: http://localhost:8080
    description: Development server
  - url: https://api-jp-m.pipihub.id
    description: Development server
  - url: https://api-jp-m.pipihub.id
    description: Production server

paths:
  /healthz:
    get:
      summary: Health check
      description: Check if the API is running
      responses:
        '200':
          description: API is healthy
          content:
            text/plain:
              schema:
                type: string
                example: "OK"

  /v1/auth/login:
    post:
      summary: User login
      description: Authenticate user and return access/refresh tokens
      tags:
        - Authentication
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoginRequest'
      responses:
        '200':
          description: Login successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoginResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Invalid credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Company or employee not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /v1/auth/refresh:
    post:
      summary: Refresh access token
      description: Get new access and refresh tokens using refresh token
      tags:
        - Authentication
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RefreshRequest'
      responses:
        '200':
          description: Token refresh successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RefreshResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Invalid or expired refresh token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /v1/auth/logout:
    post:
      summary: User logout
      description: Logout user and blacklist current access token
      tags:
        - Authentication
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Logout successful
          content:
            text/plain:
              schema:
                type: string
                example: "Logged out successfully"
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /v1/me:
    get:
      summary: Get current user info
      description: Get information about the currently authenticated user
      tags:
        - User
      security:
        - bearerAuth: []
      responses:
        '200':
          description: User information retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Employee'
        '401':
          description: Unauthorized or token revoked
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /docs:
    get:
      summary: API Documentation
      description: Swagger UI for API documentation
      responses:
        '200':
          description: HTML documentation page

  /openapi.yaml:
    get:
      summary: OpenAPI Specification
      description: Download OpenAPI specification in YAML format
      responses:
        '200':
          description: OpenAPI specification
          content:
            application/x-yaml:
              schema:
                type: string

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:
    LoginRequest:
      type: object
      required:
        - company_username
        - username
        - password
        - device_type
        - ip_address
        - timezone
        - product
        - fcm
      properties:
        company_username:
          type: string
          description: Company username/identifier
          example: "INSOM"
        username:
          type: string
          description: Employee username
          example: "fahmi1"
        password:
          type: string
          description: Employee password
          example: "password123"
        device_type:
          type: string
          description: Type of device
          example: "Android"
        ip_address:
          type: string
          description: IP address of the device
          example: "192.168.1.1"
        timezone:
          type: string
          description: Timezone of the device
          example: "Asia/Jakarta"
        product:
          type: string
          description: Product name
          example: "Japregeo"
        fcm:
          type: string
          description: Firebase Cloud Messaging token
          example: "fcm_token_abc123"

    LoginResponse:
      type: object
      properties:
        access_token:
          type: string
          description: JWT access token
          example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
        access_exp:
          type: integer
          description: Access token expiration timestamp
          example: 1640995200
        refresh_token:
          type: string
          description: Refresh token
          example: "refresh_token_abc123"
        refresh_exp:
          type: integer
          description: Refresh token expiration timestamp
          example: 1643587200
        employee:
          $ref: '#/components/schemas/Employee'
        login_history_id:
          type: integer
          description: ID of the login history record
          example: 1

    RefreshRequest:
      type: object
      required:
        - refresh_token
      properties:
        refresh_token:
          type: string
          description: Refresh token
          example: "refresh_token_abc123"

    RefreshResponse:
      type: object
      properties:
        access_token:
          type: string
          description: New JWT access token
          example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
        access_exp:
          type: integer
          description: New access token expiration timestamp
          example: 1640995200
        refresh_token:
          type: string
          description: New refresh token
          example: "refresh_token_def456"
        refresh_exp:
          type: integer
          description: New refresh token expiration timestamp
          example: 1643587200

    Employee:
      type: object
      properties:
        id:
          type: integer
          description: Employee ID
          example: 1
        company_id:
          type: integer
          description: Company ID
          example: 1
        username:
          type: string
          description: Employee username
          example: "fahmi1"
        name:
          type: string
          description: Employee full name
          example: "Fahmi"
        email:
          type: string
          description: Employee email
          example: "fahmi@insom.com"
        phone:
          type: string
          description: Employee phone number
          example: "+6281234567890"
        status:
          type: string
          description: Employee status
          example: "active"
        created_at:
          type: string
          format: date-time
          description: Creation timestamp
          example: "2024-01-01T00:00:00Z"
        updated_at:
          type: string
          format: date-time
          description: Last update timestamp
          example: "2024-01-01T00:00:00Z"

    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: "Invalid credentials"
        code:
          type: string
          description: Error code
          example: "AUTH_001"
        details:
          type: object
          description: Additional error details

tags:
  - name: Authentication
    description: Authentication and authorization endpoints
  - name: User
    description: User management endpoints
  - name: System
    description: System and health check endpoints
