{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chromalith.com/schemas/multi-channel-export-manifest-v1.json",
  "title": "Chromalith multi-channel export manifest",
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "rgb": {
      "type": "object",
      "additionalProperties": false,
      "required": ["red", "green", "blue"],
      "properties": {
        "red": { "type": "integer", "minimum": 0, "maximum": 255 },
        "green": { "type": "integer", "minimum": 0, "maximum": 255 },
        "blue": { "type": "integer", "minimum": 0, "maximum": 255 }
      }
    },
    "ink": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "name", "preview_rgb", "solidity_percent"],
      "properties": {
        "id": { "type": "string", "minLength": 1, "maxLength": 80 },
        "kind": {
          "type": "string",
          "enum": ["process", "white", "spot", "varnish", "metallic", "fluorescent"]
        },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "preview_rgb": { "$ref": "#/$defs/rgb" },
        "solidity_percent": { "type": "number", "minimum": 0, "maximum": 100 }
      }
    },
    "screening": {
      "type": "object",
      "additionalProperties": false,
      "required": ["method", "seed"],
      "properties": {
        "method": {
          "type": "string",
          "enum": ["none", "am", "fm_blue_noise", "hybrid_am_fm"]
        },
        "seed": { "type": "integer", "minimum": 0, "maximum": 4294967295 },
        "lpi": { "type": ["number", "null"], "minimum": 1, "maximum": 999.99 },
        "angle": { "type": ["number", "null"], "minimum": -180, "maximum": 180 }
      }
    }
  },
  "required": [
    "$schema",
    "schema_version",
    "created_at",
    "producer",
    "job",
    "profile",
    "pixel_modifiers",
    "channels",
    "files"
  ],
  "properties": {
    "$schema": {
      "const": "https://chromalith.com/schemas/multi-channel-export-manifest-v1.json"
    },
    "schema_version": { "const": 1 },
    "created_at": { "type": "string", "format": "date-time" },
    "producer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "phase"],
      "properties": {
        "name": { "const": "Chromalith" },
        "phase": { "const": "11.10" }
      }
    },
    "job": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "width_px",
        "height_px",
        "resolution_dpi",
        "channel_set_id"
      ],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "width_px": { "type": "integer", "minimum": 1 },
        "height_px": { "type": "integer", "minimum": 1 },
        "resolution_dpi": { "type": "number", "exclusiveMinimum": 0 },
        "channel_set_id": { "type": "string", "minLength": 1, "maxLength": 80 }
      }
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile_id",
        "profile_name",
        "process",
        "schema_version",
        "provenance_tier"
      ],
      "properties": {
        "profile_id": { "type": "string", "minLength": 1, "maxLength": 80 },
        "profile_name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "process": { "type": "string", "minLength": 1, "maxLength": 40 },
        "schema_version": { "type": "integer", "minimum": 1 },
        "provenance_tier": { "type": "string", "minLength": 1, "maxLength": 40 }
      }
    },
    "pixel_modifiers": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["feature", "profile_id", "provenance_tier", "parameters"],
        "properties": {
          "feature": {
            "type": "string",
            "enum": [
              "choke_spread",
              "component_cleanup",
              "fm_screening",
              "channel_sets",
              "underbase_refinement"
            ]
          },
          "profile_id": {
            "type": ["string", "null"],
            "minLength": 1,
            "maxLength": 80
          },
          "provenance_tier": {
            "type": ["string", "null"],
            "minLength": 1,
            "maxLength": 40
          },
          "parameters": { "type": ["object", "null"] }
        }
      }
    },
    "channels": {
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "index",
          "id",
          "name",
          "role",
          "checksum",
          "polarity",
          "ink",
          "generation",
          "screening",
          "refinement",
          "white_passes"
        ],
        "properties": {
          "index": { "type": "integer", "minimum": 0 },
          "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_-]*$" },
          "name": { "type": "string", "minLength": 1, "maxLength": 80 },
          "role": {
            "type": "string",
            "enum": ["process", "underbase", "highlight", "spot", "varnish"]
          },
          "checksum": { "type": "string", "pattern": "^crc32:[0-9a-f]{8}$" },
          "polarity": { "const": "positive_255_is_ink" },
          "ink": { "$ref": "#/$defs/ink" },
          "generation": { "type": ["object", "null"] },
          "screening": { "$ref": "#/$defs/screening" },
          "refinement": { "type": ["object", "null"] },
          "white_passes": { "type": "integer", "minimum": 1 }
        }
      }
    },
    "files": {
      "type": "array",
      "minItems": 2,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "kind"],
        "properties": {
          "name": { "type": "string", "minLength": 1 },
          "kind": {
            "type": "string",
            "enum": [
              "multi_channel_tiff",
              "channel_tiff",
              "photoshop_spot_channels",
              "channel_png",
              "manifest"
            ]
          },
          "bit_depth": { "type": "integer", "enum": [1, 8] },
          "channel_id": { "type": "string" },
          "polarity": {
            "type": "string",
            "enum": ["positive_255_is_ink", "photoshop_spot_0_is_ink"]
          }
        },
        "allOf": [
          {
            "if": { "properties": { "kind": { "const": "multi_channel_tiff" } } },
            "then": {
              "required": ["bit_depth", "polarity"],
              "properties": {
                "bit_depth": { "const": 8 },
                "polarity": { "const": "positive_255_is_ink" }
              }
            }
          },
          {
            "if": { "properties": { "kind": { "const": "channel_tiff" } } },
            "then": {
              "required": ["bit_depth", "channel_id", "polarity"],
              "properties": {
                "bit_depth": { "const": 1 },
                "polarity": { "const": "positive_255_is_ink" }
              }
            }
          },
          {
            "if": { "properties": { "kind": { "const": "photoshop_spot_channels" } } },
            "then": {
              "required": ["bit_depth", "polarity"],
              "properties": {
                "bit_depth": { "const": 8 },
                "polarity": { "const": "photoshop_spot_0_is_ink" }
              }
            }
          },
          {
            "if": { "properties": { "kind": { "const": "channel_png" } } },
            "then": {
              "required": ["bit_depth", "channel_id", "polarity"],
              "properties": {
                "bit_depth": { "const": 8 },
                "polarity": { "const": "positive_255_is_ink" }
              }
            }
          }
        ]
      }
    }
  }
}
