openapi: 3.1.0
info:
  title: "Asteon Creator API"
  version: 1.0.0
  summary: "Programmatisk tilgang til ditt eget skaper-panel — spill, builds, inntekt og analyse."
  description: "Creator-API-en lar deg gjøre fra skript det du ellers gjør i Skaper-panelet: liste spillene dine, hente versjons-historikk, lese inntekt og payout-status og dra ut analytics per spill. Alle kall tagges mot din egen bruker — du kan aldri se andre skaperes data.\n\nGenerer en `agc_*`-nøkkel under [/skaper/api-nokler](https://asteon.ai/skaper/api-nokler)."
  contact:
    name: "Asteon Support"
    email: support@asteon.ai
    url: https://asteon.ai/help
  license:
    name: "Asteon Terms of Service"
    url: https://asteon.ai/terms
servers:
  - url: https://api.asteon.ai/api
    description: Produksjon
security:
  - bearerAuth: []
tags:
  - name: Konto
    description: "Sjekk hvem token-en tilhører."
  - name: Spill
    description: "List og inspiser dine egne spill."
  - name: Builds
    description: "Versjons-historikk for utgitte builds."
  - name: Inntekt
    description: "Salg, payouts og eligible balance."
  - name: Analyse
    description: "Spillere og engasjement per spill."
paths:
  /creator/me:
    get:
      tags:
        - Konto
      summary: "Hvem er jeg?"
      description: "Returnerer bruker-id, creator-id og scopes for token-en. Bruk dette som ping for å sjekke at nøkkelen virker."
      responses:
        200:
          description: Token-info
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/MeResponse"
        401:
          "$ref": "#/components/responses/Unauthorized"
  /creator/games:
    get:
      tags:
        - Spill
      summary: "List dine spill"
      responses:
        200:
          description: "Liste over spill du eier"
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/GamesList"
        401:
          "$ref": "#/components/responses/Unauthorized"
  "/creator/games/{id}":
    get:
      tags:
        - Spill
      summary: Spill-detalj
      parameters:
        - name: id
          in: path
          required: true
          description: "Spill-id eller slug."
          schema:
            type: string
      responses:
        200:
          description: Spill-objekt
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/GameDetail"
        401:
          "$ref": "#/components/responses/Unauthorized"
        403:
          "$ref": "#/components/responses/Forbidden"
        404:
          "$ref": "#/components/responses/NotFound"
  /creator/builds:
    get:
      tags:
        - Builds
      summary: Build-historikk
      description: "Returnerer alle builds (siste 200) på tvers av dine spill, sortert nyeste først."
      responses:
        200:
          description: "Liste over builds"
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/BuildsList"
        401:
          "$ref": "#/components/responses/Unauthorized"
  /creator/earnings/summary:
    get:
      tags:
        - Inntekt
      summary: Inntekts-sammendrag
      description: "Totaler + per-spill nedbryting i et tidsvindu. Inkluderer eligible balance (saldo klar for utbetaling) og pending payouts."
      parameters:
        - name: range
          in: query
          description: "Tidsvindu, f.eks. `7d`, `30d`, `90d`. Maks 365d."
          required: false
          schema:
            type: string
            default: 30d
      responses:
        200:
          description: Inntekts-sammendrag
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/EarningsSummary"
        401:
          "$ref": "#/components/responses/Unauthorized"
  /creator/payouts:
    get:
      tags:
        - Inntekt
      summary: Payout-historikk
      description: "Inntil 100 siste payouts (alle statuser)."
      responses:
        200:
          description: Payouts
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/PayoutsList"
        401:
          "$ref": "#/components/responses/Unauthorized"
  "/creator/analytics/games/{id}":
    get:
      tags:
        - Analyse
      summary: "Analyse for ett spill"
      description: "Kjøp i tidsvinduet + total play-count og rating-snapshot. Detaljert DAU/MAU/retention er foreløpig kun tilgjengelig via session-autentisert `/api/analytics/dashboard/:projectId`."
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
        - name: range
          in: query
          required: false
          schema:
            type: string
            default: 30d
      responses:
        200:
          description: Analyse-objekt
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/GameAnalytics"
        401:
          "$ref": "#/components/responses/Unauthorized"
        403:
          "$ref": "#/components/responses/Forbidden"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: "agc_*"
      description: "Send `Authorization: Bearer agc_din_nokkel`. Generer nøkler under [/skaper/api-nokler](https://asteon.ai/skaper/api-nokler)."
  schemas:
    MeResponse:
      type: object
      properties:
        userId:
          type: string
        creatorId:
          type:
            - string
            - "null"
        displayName:
          type:
            - string
            - "null"
        scopes:
          type: array
          items:
            type: string
            enum:
              - creator:read
              - creator:write
        tokenId:
          type:
            - integer
            - "null"
    Game:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        slug:
          type: string
        status:
          type: string
          enum:
            - draft
            - review
            - published
            - rejected
        playCount:
          type: integer
        downloadCount:
          type: integer
        rating:
          type: number
        ratingCount:
          type: integer
    GamesList:
      type: object
      properties:
        games:
          type: array
          items:
            "$ref": "#/components/schemas/Game"
    GameDetail:
      type: object
      properties:
        game:
          allOf:
            - "$ref": "#/components/schemas/Game"
            - type: object
              properties:
                tags:
                  type: array
                  items:
                    type: string
                category:
                  type:
                    - string
                    - "null"
                coverImage:
                  type:
                    - string
                    - "null"
                  format: uri
    Build:
      type: object
      properties:
        id:
          type: string
        projectId:
          type: string
        target:
          type: string
          example: web
        version:
          type: string
          example: 1.0.3
        status:
          type: string
          enum:
            - pending
            - building
            - ready
            - deployed
            - failed
        createdAt:
          type: string
          format: date-time
        completedAt:
          type:
            - string
            - "null"
          format: date-time
    BuildsList:
      type: object
      properties:
        builds:
          type: array
          items:
            "$ref": "#/components/schemas/Build"
    EarningsSummary:
      type: object
      properties:
        range:
          type: object
          properties:
            days:
              type: integer
            since:
              type: string
              format: date-time
        totals:
          type: object
          properties:
            revenue:
              type: number
              description: "Netto inntekt etter platform-fee."
            sales:
              type: integer
            grossEstimate:
              type: number
              description: "Implisitt brutto før 15 % platform-fee."
            paidOut:
              type: number
            pendingPayout:
              type: number
            eligibleBalance:
              type: number
              description: "Klar for utbetaling."
        byGame:
          type: array
          items:
            type: object
            properties:
              gameId:
                type: string
              revenue:
                type: number
              sales:
                type: integer
    Payout:
      type: object
      properties:
        id:
          type: integer
        status:
          type: string
          enum:
            - pending
            - processing
            - completed
            - failed
        totalAmount:
          type: number
        currency:
          type: string
          example: USD
        createdAt:
          type: string
          format: date-time
        completedAt:
          type:
            - string
            - "null"
          format: date-time
    PayoutsList:
      type: object
      properties:
        payouts:
          type: array
          items:
            "$ref": "#/components/schemas/Payout"
    GameAnalytics:
      type: object
      properties:
        range:
          type: object
          properties:
            days:
              type: integer
            since:
              type: string
              format: date-time
        gameId:
          type: string
        purchases:
          type: integer
        playCount:
          type: integer
        rating:
          type: number
        ratingCount:
          type: integer
        note:
          type: string
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        code:
          type: string
  responses:
    Unauthorized:
      description: "Manglende eller ugyldig `agc_*`-token."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
    Forbidden:
      description: "Token har ikke tilgang til denne ressursen."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
    NotFound:
      description: "Ressursen finnes ikke."
      content:
        application/json:
          schema:
            "$ref": "#/components/schemas/Error"
