openapi: "3.0.0"


################################################################################
# General Information
info:
  description: The ICT Platform Web Service that exposes the EcoCreditCalculator library functionality via a RESTful API.
  version: 1.0.2
  title: ICT Platform Eco-credits Calculator Web Service
  contact:
    name: Miltiadis Koutsokeras
    email: miltos.koutsokeras@iccs.gr
    url: https://www.iccs.gr/

# Deployed server endpoints
servers:
  - url: https://circ4life.iccs.gr/EcoCreditCalculator
    description: CIRC4Life ICT platform.
  - url: http://127.0.0.1:8081/EcoCreditCalculator
    description: Local debugging standalone server.
################################################################################


################################################################################
# Components
components:
  schemas:
    # The weeesparameters and foodparameters should be set according to the
    # producttype.
    EcoCreditParameters:
      type: object
      required:
        - producttype
      properties:
        producttype:
          # Always present
          $ref: "CommonOpenAPI.yaml#/components/schemas/ProductType"
        weeesparameters:
          # Present only in WEEEs
          $ref: "#/components/schemas/WEEEsParameters"
        foodparameters:
          # Present only in Food waste
          $ref: "#/components/schemas/FoodParameters"

    weightA:
      description: Constant parameter weight A to be multiplied with product materials exergy.
      type: number
      format: double
      minimum: 0

    weightB:
      description: Constant parameter weight B to be multiplied with End of Life state factor.
      type: number
      format: double
      minimum: 0

    weightC:
      description: Constant parameter weight C to be multiplied by Lifetime Factor.
      type: number
      format: double
      minimum: 0

    MaterialFactors:
      description: Encapsulation of material recyclability and rarity factors.
      type: object
      properties:
        mass:
          description: Mass in grams.
          type: number
          format: double
          minimum: 0.0
        rarity:
          description: Rarity is a measure of the physical value of raw materials.
          type: number
          format: double
          minimum: 0.0
        recyclability:
          description: Weight of recycling friendliness of material.
          type: number
          format: double
          minimum: 0.0

    WEEEsParameters:
      description: Parameters and factors of Waste Electrical and Electronic Equipment.
      type: object
      required:
        - weeestype
        - eolstate
        - yearsofuse
        - monthsofuse
        - weightA
        - weightB
        - weightC
        - materialfactors
      properties:
        weeestype:
          $ref: "CommonOpenAPI.yaml#/components/schemas/UNUkey"
        eolstate:
          $ref: "CommonOpenAPI.yaml#/components/schemas/EndOfLifeState"
        yearsofuse:
          $ref: "CommonOpenAPI.yaml#/components/schemas/yearsofuse"
        monthsofuse:
          $ref: "CommonOpenAPI.yaml#/components/schemas/monthsofuse"
        weightA:
          $ref: "#/components/schemas/weightA"
        weightB:
          $ref: "#/components/schemas/weightB"
        weightC:
          $ref: "#/components/schemas/weightC"
        materialfactors:
          type: array
          items:
            $ref: "#/components/schemas/MaterialFactors"

    chemical_exergy:
      description: Organic urban waste chemical exergy, which is the energy contained in the waste.
      type: number
      format: double
      minimum: 0

    mass:
      description: Mass of waste. The unit of measurement will change the scale of the final Eco-credit result, so in order to compare Eco-credits the same mass unit (Kg, g) should be used.
      type: number
      format: double
      minimum: 0

    weightD:
      description: The coefficient D factor, responsible for converting the exergy in the wastes to user incentive for proper waste disposal.
      type: number
      format: double
      minimum: 0

    FoodParameters:
      description: Parameters and factors of Food and Urban Organic product waste.
      type: object
      required:
        - chemical_exergy
        - mass
        - weightD
      properties:
        chemical_exergy:
          $ref: "#/components/schemas/chemical_exergy"
        mass:
          $ref: "#/components/schemas/mass"
        weightD:
          $ref: "#/components/schemas/weightD"
################################################################################


################################################################################
# Resource path URI endpoints
paths:
  # Calculate the Eco-credits from all possible parameters.
  # VALID USER SESSION/ACCESS TOKEN REQUIRED
  /ecocredits:
    post:
      description: Calculate the Eco-credits of a recycled product with the specified parameters according to the formula of Eq. 1 in Deliverable 2.4.
      operationId: EcoCreditsPOST
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/EcoCreditParameters"
      responses:
        '200':
          description: The Eco-credits result value.
          content:
            application/json:
              schema:
                $ref: "CommonOpenAPI.yaml#/components/schemas/EcoCredits"
        # Any response that is not HTTP/200 OK is considered an error.
        default:
          $ref: "CommonOpenAPI.yaml#/components/responses/DefaultError"

  # Calculate the Eco-credits from product ID. This calculates the Eco-credits
  # for a specific product.
  # VALID USER SESSION/ACCESS TOKEN REQUIRED
  /ecocredits/product/{productid}/{years}/{extramonths}/{eolstate}:
    get:
      description: USER_R_02 Get Eco-credits from evaluated recycled product.
      operationId: EcoCreditsProductGET
      parameters:
        - in: path
          name: productid
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/ProductID"
        - in: path
          name: years
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/yearsofuse"
        - in: path
          name: extramonths
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/monthsofuse"
        - in: path
          name: eolstate
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/EndOfLifeState"
      responses:
        '200':
          description: The Eco-credits result value.
          content:
            application/json:
              schema:
                $ref: "CommonOpenAPI.yaml#/components/schemas/EcoCredits"
        # Any response that is not HTTP/200 OK is considered an error.
        default:
          $ref: "CommonOpenAPI.yaml#/components/responses/DefaultError"

  # Calculate the Eco-credits from product HS key code, lifetime and state
  # parameters. This endpoint will return the Eco-credits that correspond to a
  # general classification instead of exact product parameters. The HS key
  # defines the product type class and from this a generic list of parameters
  # contribute to the calculation.
  # VALID USER SESSION/ACCESS TOKEN REQUIRED
  /ecocredits/{hskey}/{years}/{extramonths}/{eolstate}:
    get:
      description: USER_R_02 Get Eco-credits from evaluated recycled product type.
      operationId: EcoCreditsGET
      parameters:
        - in: path
          name: hskey
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/HSkey"
        - in: path
          name: years
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/yearsofuse"
        - in: path
          name: extramonths
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/monthsofuse"
        - in: path
          name: eolstate
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/EndOfLifeState"
      responses:
        '200':
          description: The Eco-credits result value.
          content:
            application/json:
              schema:
                $ref: "CommonOpenAPI.yaml#/components/schemas/EcoCredits"
        # Any response that is not HTTP/200 OK is considered an error.
        default:
          $ref: "CommonOpenAPI.yaml#/components/responses/DefaultError"

  # Calculate the Eco-credits from Waste Electrical and Electronic Equipment UNU
  # key code, lifetime and state parameters. This endpoint will return the
  # Eco-credits that correspond to a general classification instead of a
  # specific product parameters. The UNU key defines the electronics product
  # type class and from this a generic list of parameters contribute to the
  # calculation.
  # VALID USER SESSION/ACCESS TOKEN REQUIRED
  /ecocredits/weees/{unukey}/{years}/{extramonths}/{eolstate}/{A}/{B}/{C}:
    get:
      description: Get WEEE product Eco-credits by supplying all parameters to path.
      operationId: EcoCreditsWEEEsGET
      parameters:
        - in: path
          name: unukey
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/UNUkey"
        - in: path
          name: years
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/yearsofuse"
        - in: path
          name: extramonths
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/monthsofuse"
        - in: path
          name: eolstate
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/EndOfLifeState"
        - in: path
          name: A
          required: true
          schema:
            $ref: "#/components/schemas/weightA"
        - in: path
          name: B
          required: true
          schema:
            $ref: "#/components/schemas/weightB"
        - in: path
          name: C
          required: true
          schema:
            $ref: "#/components/schemas/weightC"
      responses:
        '200':
          description: The Eco-credits result value.
          content:
            application/json:
              schema:
                $ref: "CommonOpenAPI.yaml#/components/schemas/EcoCredits"
        # Any response that is not HTTP/200 OK is considered an error.
        default:
          $ref: "CommonOpenAPI.yaml#/components/responses/DefaultError"

  # Get the Waste Electrical and Electronic Equipment Weibull Lifespan
  # distribution factor value.
  # VALID USER SESSION/ACCESS TOKEN REQUIRED
  /ecocredits/weees/lifetime_factor/{unukey}/{years}/{extramonths}:
    get:
      description: Get WEEE product Lifespan Weibull Distribution value.
      operationId: LifeSpanFactorWEEEsGET
      parameters:
        - in: path
          name: unukey
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/UNUkey"
        - in: path
          name: years
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/yearsofuse"
        - in: path
          name: extramonths
          required: true
          schema:
            $ref: "CommonOpenAPI.yaml#/components/schemas/monthsofuse"
      responses:
        '200':
          description: The Weibull Lifespan distribution factor result value.
          content:
            application/json:
              schema:
                type: number
                format: double
                minimum: 0.0
        # Any response that is not HTTP/200 OK is considered an error.
        default:
          $ref: "CommonOpenAPI.yaml#/components/responses/DefaultError"

  # Calculate the Eco-credits from Urban Food Waste exergy, mass and D constant
  # parameters. Since the parameters passed are specific for each food product
  # there is no need to provide an API for product types as in electronics
  # above.
  # VALID USER SESSION/ACCESS TOKEN REQUIRED
  /ecocredits/food/{exergy}/{mass}/{D}:
    get:
      description: Get food Eco-credits by supplying all parameters in path.
      operationId: EcoCreditsFoodGET
      parameters:
        - in: path
          name: exergy
          required: true
          schema:
            $ref: "#/components/schemas/FoodParameters/properties/chemical_exergy"
        - in: path
          name: mass
          required: true
          schema:
            $ref: "#/components/schemas/FoodParameters/properties/mass"
        - in: path
          name: D
          required: true
          schema:
            $ref: "#/components/schemas/FoodParameters/properties/weightD"
      responses:
        '200':
          description: The Eco-credits result value.
          content:
            application/json:
              schema:
                $ref: "CommonOpenAPI.yaml#/components/schemas/EcoCredits"
        # Any response that is not HTTP/200 OK is considered an error.
        default:
          $ref: "CommonOpenAPI.yaml#/components/responses/DefaultError"
################################################################################
