openapi: 3.1.0
info:
  title: Api
  version: 0.1.0
  description: OEN Klaim Penghargaan API
servers:
  - url: /api
    description: Base API path
tags:
  - name: health
    description: Health operations
  - name: events
    description: Event management
  - name: transactions
    description: Transaction management
  - name: inventory
    description: Stock/inventory management
  - name: settings
    description: App settings
paths:
  /healthz:
    get:
      operationId: healthCheck
      tags: [health]
      summary: Health check
      responses:
        "200":
          description: Healthy
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HealthStatus"

  /events:
    get:
      operationId: listEvents
      tags: [events]
      summary: List all events
      responses:
        "200":
          description: List of events
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Event"
    post:
      operationId: createEvent
      tags: [events]
      summary: Create a new event
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateEventRequest"
      responses:
        "201":
          description: Created event
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Event"

  /events/{slug}:
    get:
      operationId: getEvent
      tags: [events]
      summary: Get event by slug
      parameters:
        - name: slug
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Event details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Event"
        "404":
          description: Not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    put:
      operationId: updateEvent
      tags: [events]
      summary: Update event
      parameters:
        - name: slug
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateEventRequest"
      responses:
        "200":
          description: Updated event
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Event"
    delete:
      operationId: deleteEvent
      tags: [events]
      summary: Delete event
      parameters:
        - name: slug
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Deleted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"

  /transactions:
    get:
      operationId: listTransactions
      tags: [transactions]
      summary: List all transactions
      parameters:
        - name: eventSlug
          in: query
          required: false
          schema:
            type: string
        - name: status
          in: query
          required: false
          schema:
            type: string
      responses:
        "200":
          description: List of transactions
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Transaction"
    post:
      operationId: createTransaction
      tags: [transactions]
      summary: Submit a claim transaction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateTransactionRequest"
      responses:
        "201":
          description: Created transaction
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Transaction"

  /transactions/{id}:
    get:
      operationId: getTransaction
      tags: [transactions]
      summary: Get transaction by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Transaction details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Transaction"
    patch:
      operationId: updateTransactionStatus
      tags: [transactions]
      summary: Update transaction status (admin)
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateStatusRequest"
      responses:
        "200":
          description: Updated transaction
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Transaction"

  /inventory:
    get:
      operationId: listInventory
      tags: [inventory]
      summary: Get all inventory items
      responses:
        "200":
          description: Inventory list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/InventoryItem"

  /inventory/{itemKey}:
    put:
      operationId: updateInventory
      tags: [inventory]
      summary: Update stock for an inventory item
      parameters:
        - name: itemKey
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateInventoryRequest"
      responses:
        "200":
          description: Updated inventory item
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InventoryItem"

  /settings:
    get:
      operationId: getSettings
      tags: [settings]
      summary: Get all settings
      responses:
        "200":
          description: Settings object
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Settings"
    put:
      operationId: updateSettings
      tags: [settings]
      summary: Update settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateSettingsRequest"
      responses:
        "200":
          description: Updated settings
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Settings"

components:
  schemas:
    HealthStatus:
      type: object
      properties:
        status:
          type: string
      required:
        - status

    ErrorResponse:
      type: object
      properties:
        error:
          type: string
      required:
        - error

    SuccessResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
      required:
        - success
        - message

    Event:
      type: object
      properties:
        id:
          type: integer
        slug:
          type: string
        namaEvent:
          type: string
        deskripsi:
          type: string
        whatsappNumber:
          type: string
        isActive:
          type: boolean
        createdAt:
          type: string
        updatedAt:
          type: string
      required:
        - id
        - slug
        - namaEvent
        - whatsappNumber
        - isActive
        - createdAt
        - updatedAt

    CreateEventRequest:
      type: object
      properties:
        slug:
          type: string
        namaEvent:
          type: string
        deskripsi:
          type: string
        whatsappNumber:
          type: string
        isActive:
          type: boolean
      required:
        - slug
        - namaEvent
        - whatsappNumber

    Transaction:
      type: object
      properties:
        id:
          type: integer
        transactionId:
          type: string
        eventId:
          type: integer
        eventSlug:
          type: string
        eventName:
          type: string
        nama:
          type: string
        sekolah:
          type: string
        mapel:
          type: string
        penghargaan:
          type: string
        paket:
          type: string
        alamat:
          type: string
        kecamatan:
          type: string
        kabupaten:
          type: string
        provinsi:
          type: string
        kodepos:
          type: string
        nomorwa:
          type: string
        pembayaran:
          type: string
        totalRincian:
          type: string
        totalAmount:
          type: integer
        status:
          type: string
        adminNotes:
          type: string
        createdAt:
          type: string
        updatedAt:
          type: string
      required:
        - id
        - transactionId
        - eventId
        - eventSlug
        - eventName
        - nama
        - sekolah
        - mapel
        - penghargaan
        - paket
        - nomorwa
        - pembayaran
        - totalRincian
        - totalAmount
        - status
        - createdAt
        - updatedAt

    CreateTransactionRequest:
      type: object
      properties:
        eventSlug:
          type: string
        nama:
          type: string
        sekolah:
          type: string
        mapel:
          type: string
        penghargaan:
          type: string
        paket:
          type: string
        alamat:
          type: string
        kecamatan:
          type: string
        kabupaten:
          type: string
        provinsi:
          type: string
        kodepos:
          type: string
        nomorwa:
          type: string
        pembayaran:
          type: string
        totalRincian:
          type: string
        totalAmount:
          type: integer
      required:
        - eventSlug
        - nama
        - sekolah
        - mapel
        - penghargaan
        - paket
        - nomorwa
        - pembayaran
        - totalRincian
        - totalAmount

    UpdateStatusRequest:
      type: object
      properties:
        status:
          type: string
          enum: [belum_bayar, diproses, packing, pengiriman, selesai]
        adminNotes:
          type: string
      required:
        - status

    InventoryItem:
      type: object
      properties:
        id:
          type: integer
        itemKey:
          type: string
        itemName:
          type: string
        stock:
          type: integer
        updatedAt:
          type: string
      required:
        - id
        - itemKey
        - itemName
        - stock
        - updatedAt

    UpdateInventoryRequest:
      type: object
      properties:
        stock:
          type: integer
      required:
        - stock

    Settings:
      type: object
      properties:
        qrisImageUrl:
          type: string
        qrisAccountName:
          type: string
        qrisAccountNumber:
          type: string
        updatedAt:
          type: string
      required:
        - qrisImageUrl
        - qrisAccountName
        - qrisAccountNumber
        - updatedAt

    UpdateSettingsRequest:
      type: object
      properties:
        qrisImageUrl:
          type: string
        qrisAccountName:
          type: string
        qrisAccountNumber:
          type: string
