{
  "openapi": "3.0.0",
  "info": {
    "title": "Proalpha ERP Resource Calendar API V1",
    "version": "1.0.0",
    "description": "API for updating resource calendars"
  },
  "servers": [
    {
      "url": "{schema}://{host}:{port}/api/web/v1/pps/base/resourceCalendar",
      "description": "The base URL is environment-specific and should be configured accordingly",
      "variables": {
        "schema": {
          "default": "http",
          "description": "The schema (http, https)"
        },
        "host": {
          "default": "localhost",
          "description": "The host name"
        },
        "port": {
          "default": "35053",
          "description": "The port"
        }
      }
    }
  ],
  "security": [
    {
      "BasicAuth": []
    }
  ],
  "tags": [
    {
      "name": "Resource Calendar",
      "description": "Sets the resource calendar for a specific resource and day"
    },
    {
      "name": "Health",
      "description": "Health Check endpoint for the API."
    }
  ],
  "paths": {
    "/": {
      "post": {
        "summary": "Set Resource calendar",
        "operationId": "SetResourceCalendar",
        "tags": [
          "Resource Calendar"
        ],
        "parameters": [
          {
            "name": "x-caller-id",
            "description": "Unique ID of the caller of an API. Later on, a call / dependency graph can automatically be generated out of the access logs based on the caller id.\n",
            "in": "header",
            "schema": {
              "type": "string",
              "example": "tisoware-MES-11.2.0"
            }
          },
          {
            "name": "x-correlation-id",
            "description": "Unique ID of the use case, user interaction, etc. which originally triggered a chain of API calls. The ID is included in each log message and can therefore be used to easily retrieve all correlated logs distributed across multiple products / services. A new ID is generated if no correlation id is included in an inbound request.",
            "in": "header",
            "schema": {
              "type": "string",
              "example": "DataEntryBOMLine-f65a90e9-6e1c-4a23-a249-68b8f033a272"
            }
          },
          {
            "name": "x-pa-company",
            "description": "ID of the company (unique in the context of a tenant)\n",
            "in": "header",
            "schema": {
              "type": "string",
              "example": "110"
            },
            "required": true
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResourceCalendars"
              }
            }
          }
        },
        "description": "Sets the calendar of a resource.\n",
        "responses": {
          "200": {
            "$ref": "#/components/responses/SuccessfullChange"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Health Check endpoint",
        "operationId": "healthCheck",
        "tags": [
          "Health"
        ],
        "responses": {
          "200": {
            "description": "Healthy or Degraded - The component is either functioning correctly or in a degraded state.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "Healthy",
                    "Degraded"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Unhealthy - The component is unhealthy or an unhandled exception occurred.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "Unhealthy"
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BasicAuth": {
        "type": "http",
        "scheme": "basic"
      }
    },
    "responses": {
      "SuccessfullChange": {
        "description": "Successful response after changing the calendar.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/successfullChange"
            }
          }
        }
      },
      "NotFoundError": {
        "description": "The specified resource or id was not found.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "UnauthorizedError": {
        "description": "Insufficient authorization.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "InternalServerError": {
        "description": "Internal server error.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "ResourceCalendars": {
        "description": "List of calendar day to be changed.",
        "type": "object",
        "required": [
          "resourceGuid",
          "daysChanged",
          "daysDeleted"
        ],
        "properties": {
          "resourceGuid": {
            "description": "Globally unique id of the resource master whose calendar has to be changed.",
            "type": "string",
            "pattern": "^[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}$",
            "maxLength": 36,
            "example": "8acea1a7-0026-96ac-dc11-16b9749f75b4"
          },
          "rangeStartDate": {
            "description": "start date of the changed date range",
            "type": "string",
            "format": "date",
            "example": "2024-04-27"
          },
          "rangeEndDate": {
            "description": "end date of the changed date range",
            "type": "string",
            "format": "date",
            "example": "2024-04-27"
          },
          "timeBlockOrigin": {
            "description": "Origin of the time block. Defines the system that changed this block.",
            "type": "string",
            "enum": [
              "bde",
              "other"
            ],
            "example": "bde",
            "default": "other"
          },
          "daysChanged": {
            "description": "Array of days where all time blocks will be deleted.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DayChanges"
            }
          },
          "daysDeleted": {
            "description": "Array of changed claendar days.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DaysDeleted"
            }
          }
        }
      },
      "DayChanges": {
        "description": "list of changed days",
        "type": "object",
        "required": [
          "date",
          "overwriteMethod",
          "blocks"
        ],
        "properties": {
          "date": {
            "description": "Date of the changed time blocks.",
            "type": "string",
            "format": "date",
            "example": "2024-04-27"
          },
          "overwriteMethod": {
            "description": "Method on how to write the time blocks and what should be preserved from the standard calendar.\nThe options are:\n  # OverwriteStandard -> The blocks will completely overwrite the standard calendar time blocks. \n  # StandardIntensity -> The time blocks of the standard calendar will preserved, the intensity will be adjusted.\n  # StandardOverloadIntensity -> The time blocks of the standard calendar will preserved, the overload intensity will be adjusted.\n",
            "type": "string",
            "enum": [
              "OverwriteStandard",
              "StandardIntensity",
              "StandardOverloadIntensity"
            ],
            "example": "StandardIntensity",
            "default": "OverwriteStandard"
          },
          "blocks": {
            "description": "List of changed time blocks for the date.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlockChange"
            }
          }
        }
      },
      "BlockChange": {
        "type": "object",
        "required": [
          "blockStartTime",
          "blockEndTime"
        ],
        "properties": {
          "blockStartTime": {
            "description": "Start time of the changed time block. This time is always considered as defined in the origin time zone of the resource.",
            "type": "string",
            "pattern": "^([0-1]\\d|2[0-3]):([0-5]\\d)$",
            "example": "08:00"
          },
          "blockEndTime": {
            "description": "End time of the changed time block. This time is always considered as defined in the origin time zone of the resource.",
            "type": "string",
            "pattern": "^([0-1]\\d|2[0-3]):([0-5]\\d)$",
            "example": "16:00"
          },
          "intensity": {
            "description": "Defined intensity for the time block.",
            "type": "number",
            "minimum": 0,
            "maximum": 999999.99,
            "default": 1
          },
          "overloadIntensity": {
            "description": "Defined overload intensity for the time block.",
            "type": "number",
            "minimum": 0,
            "maximum": 999999.99,
            "default": 0
          }
        }
      },
      "DaysDeleted": {
        "description": "One change request for the resource calendar",
        "type": "object",
        "required": [
          "date"
        ],
        "properties": {
          "date": {
            "description": "Date where all time will be deleted.",
            "type": "string",
            "format": "date",
            "example": "2024-04-28"
          }
        }
      },
      "successfullChange": {
        "description": "Successful calendar change.",
        "type": "object",
        "properties": {
          "message": {
            "description": "A human-readable message providing a response message.",
            "type": "string"
          }
        }
      },
      "Error": {
        "description": "Error information.",
        "type": "object",
        "properties": {
          "errorCode": {
            "description": "A unique identifier for the type of error that occurred.",
            "type": "string"
          },
          "message": {
            "description": "A human-readable message providing more details about the error.",
            "type": "string"
          },
          "details": {
            "description": "A list of detailed error messages or issues related to specific request parameters.",
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}
