{
  "$id": "https://www.hestia.earth/schema-data/json-schema/Transformation.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$comment": "Schema version 39.0.1",
  "title": "Transformation",
  "description": "The Transformation of one [Product](/schema/Product) to a new Product in the same [Cycle](/schema/Cycle). One Transformation can follow another and they can be linked using <code>[transformationId](/schema/Transformation#transformationId)</code>. Environmental impacts created during Transformations are then included in the [Impact Assessment](/schema/ImpactAssessment). This means that Transformations should be used to represent any processes which are required to get the Product to its marketable form or to manage any waste that is created during production. In general, any essential grain drying, crop grading, and animal excreta management should be represented using Transformations.\n",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "type": {
      "type": "string",
      "description": "Type of the Node",
      "default": "Transformation",
      "enum": [
        "Transformation"
      ]
    },
    "@type": {
      "type": "string",
      "description": "Type of the Node",
      "default": "Transformation",
      "enum": [
        "Transformation"
      ],
      "extend": true
    },
    "transformationId": {
      "type": "string",
      "pattern": "^[\\w\\-\\.\\s\\(\\)]+$",
      "description": "An identifier for each Transformation which must be unique within the Cycle.",
      "examples": [
        "second-transformation"
      ],
      "exportDefaultCSV": true
    },
    "term": {
      "$ref": "./Term-deep.json#",
      "description": "A reference to the Term describing the process or operation for transforming the Product.",
      "examples": [
        {
          "@id": "compostingInVessel",
          "@type": "Term",
          "name": "Composting - In Vessel",
          "termType": "excretaManagement"
        }
      ],
      "searchable": true,
      "exportDefaultCSV": true
    },
    "description": {
      "type": "string",
      "description": "A description of the Transformation process or operation, including information not captured with other fields.",
      "examples": [],
      "exportDefaultCSV": true
    },
    "startDate": {
      "type": "string",
      "description": "The start date of the Transformation if different from the start date of the Cycle in ISO 8601 format (YYYY-MM-DD, YYYY-MM, or YYYY).",
      "examples": [],
      "datePattern": true,
      "exportDefaultCSV": true
    },
    "endDate": {
      "type": "string",
      "description": "The end date of the Transformation if different from the end date of the Cycle in ISO 8601 format (YYYY-MM-DD, YYYY-MM, or YYYY).",
      "examples": [],
      "datePattern": true,
      "exportDefaultCSV": true
    },
    "transformationDuration": {
      "type": "number",
      "description": "The duration of the Transformation in days. Defaulting to cycleDuration when not provided.",
      "examples": [
        300
      ],
      "exclusiveMinimum": 0,
      "exportDefaultCSV": true
    },
    "previousTransformationId": {
      "type": "string",
      "description": "The transformationId of the previous Transformation. This is used to link Transformations, so that a share of the products from the previous Transformation become the inputs of the current Transformation. If this field is not specified, the inputs of the Transformation come from the Cycle.",
      "examples": [
        "first-transformation"
      ],
      "exportDefaultCSV": true
    },
    "transformedShare": {
      "type": "number",
      "minimum": 0,
      "maximum": 100,
      "description": "The share of Products from the Cycle or the previous Transformation that enter the current Transformation. This field is useful when the physical quantities of Products being transformed are unknown, but the share transformed is known. For example, if Excreta, dairy cattle (kg mass) is a Product of a Cycle, transformedShare = 50, and Excreta, dairy cattle (kg mass) is an Input into this Transformation, 50% of the excreta is an Input to this Transformation. If there are more than one Product being transformed, transformedShare applies equally to all Products.",
      "examples": [
        100
      ],
      "exportDefaultCSV": true
    },
    "site": {
      "$ref": "./Site-deep.json#",
      "description": "If the Cycle occurred on multiple Sites, the Site where this Transformation occurred. Use transformedShare to apportion the transformed Product across each Site.",
      "examples": [],
      "searchable": true,
      "exportDefaultCSV": true
    },
    "properties": {
      "type": "array",
      "items": {
        "$ref": "./Property.json#"
      },
      "description": "A list of Properties of the Transformation.",
      "examples": [],
      "exportDefaultCSV": true,
      "uniqueArrayItem": [
        "term.@id",
        "key.@id",
        "date",
        "startDate",
        "endDate"
      ]
    },
    "inputs": {
      "type": "array",
      "items": {
        "$ref": "./Input.json#"
      },
      "description": "The Inputs into the Transformation.",
      "examples": [
        [
          {
            "@type": "Input",
            "term": {
              "@id": "excretaBeefCattleFeedlotFedKgN",
              "@type": "Term",
              "name": "Excreta, beef cattle, feedlot fed (kg N)",
              "units": "kg N",
              "termType": "excreta"
            },
            "value": [
              150
            ],
            "fromCycle": true
          },
          {
            "@type": "Input",
            "term": {
              "@id": "rapeseedStraw",
              "@type": "Term",
              "name": "Rapeseed, straw",
              "units": "kg",
              "termType": "crop"
            },
            "value": [
              25
            ],
            "fromCycle": false
          }
        ]
      ],
      "searchable": true,
      "exportDefaultCSV": true,
      "uniqueArrayItem": [
        "term.@id",
        "dates",
        "startDate",
        "endDate",
        "fromCycle",
        "transport.term.@id",
        "operation.@id",
        "country.@id",
        "region.@id",
        "impactAssessment.id"
      ]
    },
    "emissions": {
      "type": "array",
      "items": {
        "$ref": "./Emission.json#"
      },
      "description": "The Emissions created from the Transformation.",
      "examples": [
        [
          {
            "@type": "Emission",
            "term": {
              "@id": "ch4ToAirExcreta",
              "@type": "Term",
              "name": "CH4, to air, excreta",
              "units": "kg CH4",
              "termType": "emission"
            },
            "value": [
              8.7
            ],
            "methodModel": {
              "@id": "emepEea2019",
              "@type": "Term",
              "name": "EMEA-EEA (2019)",
              "termType": "model"
            },
            "methodTier": "tier 2"
          }
        ]
      ],
      "searchable": true,
      "exportDefaultCSV": true,
      "uniqueArrayItem": [
        "term.@id",
        "dates",
        "startDate",
        "endDate",
        "depthUpper",
        "depthLower",
        "inputs.@id",
        "transport.@id",
        "operation.@id"
      ]
    },
    "products": {
      "type": "array",
      "items": {
        "$ref": "./Product.json#"
      },
      "description": "The Products created from the Transformation.",
      "examples": [
        [
          {
            "@type": "Product",
            "term": {
              "@id": "excretaMixturesKgN",
              "@type": "Term",
              "name": "Excreta mixtures (kg N)",
              "units": "kg N",
              "termType": "excreta"
            },
            "value": [
              160
            ]
          }
        ]
      ],
      "searchable": true,
      "exportDefaultCSV": true,
      "uniqueArrayItem": [
        "term.@id",
        "dates",
        "startDate",
        "endDate",
        "variety",
        "fate"
      ]
    },
    "practices": {
      "type": "array",
      "items": {
        "$ref": "./Practice.json#"
      },
      "description": "The Practices used during the Transformation.",
      "examples": [],
      "searchable": true,
      "exportDefaultCSV": true,
      "uniqueArrayItem": [
        "term.@id",
        "key.@id",
        "dates",
        "startDate",
        "endDate",
        "areaPercent",
        "ownershipStatus"
      ]
    },
    "schemaVersion": {
      "type": "string",
      "description": "The version of the schema when these data were created.",
      "examples": [],
      "internal": true
    },
    "added": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "A list of fields that have been added to the original dataset.",
      "examples": [],
      "internal": true
    },
    "addedVersion": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "A list of versions of the model used to add these fields.",
      "examples": [],
      "internal": true
    },
    "updated": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "A list of fields that have been updated on the original dataset.",
      "examples": [],
      "internal": true
    },
    "updatedVersion": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "A list of versions of the model used to update these fields.",
      "examples": [],
      "internal": true
    }
  },
  "allOf": [
    {
      "if": {
        "required": [
          "term"
        ]
      },
      "then": {
        "properties": {
          "term": {
            "properties": {
              "termType": {
                "enum": [
                  "excretaManagement",
                  "wasteManagement",
                  "operation"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "emissions"
        ]
      },
      "then": {
        "properties": {
          "emissions": {
            "items": {
              "properties": {
                "term": {
                  "not": {
                    "required": [
                      "transformation"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "inputs"
        ]
      },
      "then": {
        "properties": {
          "inputs": {
            "items": {
              "required": [
                "fromCycle"
              ]
            }
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "inputs"
        ]
      },
      "then": {
        "properties": {
          "inputs": {
            "items": {
              "not": {
                "required": [
                  "producedInCycle"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "practices"
        ]
      },
      "then": {
        "properties": {
          "practices": {
            "items": {
              "properties": {
                "term": {
                  "properties": {
                    "termType": {
                      "not": {
                        "enum": [
                          "excretaManagement",
                          "wasteManagement"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "anyOf": [
        {
          "properties": {
            "inputs": {
              "items": {
                "required": [
                  "value"
                ]
              }
            }
          }
        },
        {
          "required": [
            "transformedShare"
          ]
        }
      ]
    }
  ],
  "oneOf": [
    {
      "required": [
        "@type"
      ]
    },
    {
      "required": [
        "type"
      ]
    }
  ],
  "required": [
    "transformationId",
    "term"
  ]
}