/* tslint:disable */
// generated by typescript-json-validator
import {inspect} from 'util';
import Ajv = require('ajv');
import CacheFile from './CacheFile';
export const ajv = new Ajv({"allErrors":true,"coerceTypes":false,"format":"fast","nullable":true,"unicode":true,"uniqueItems":true,"useDefaults":true});

ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));

export {CacheFile};
export const CacheFileSchema = {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "defaultProperties": [
  ],
  "definitions": {
    "CachedUIPack": {
      "defaultProperties": [
      ],
      "properties": {
        "downloadTimestamp": {
          "type": "number"
        },
        "localChecksum": {
          "type": "string"
        },
        "localFilePath": {
          "type": "string"
        },
        "packInfo": {
          "$ref": "#/definitions/UIPackInfo"
        },
        "status": {
          "anyOf": [
            {
              "defaultProperties": [
              ],
              "properties": {
                "type": {
                  "enum": [
                    "valid"
                  ],
                  "type": "string"
                }
              },
              "required": [
                "type"
              ],
              "type": "object"
            },
            {
              "defaultProperties": [
              ],
              "properties": {
                "reason": {
                  "type": "string"
                },
                "timestamp": {
                  "type": "number"
                },
                "type": {
                  "enum": [
                    "invalid"
                  ],
                  "type": "string"
                }
              },
              "required": [
                "reason",
                "timestamp",
                "type"
              ],
              "type": "object"
            }
          ]
        }
      },
      "required": [
        "downloadTimestamp",
        "localChecksum",
        "localFilePath",
        "packInfo",
        "status"
      ],
      "type": "object"
    },
    "UIPackInfo": {
      "defaultProperties": [
      ],
      "properties": {
        "channel": {
          "type": "string"
        },
        "requiredClientVersion": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "version": {
          "type": "string"
        },
        "versions_hash": {
          "type": "string"
        }
      },
      "required": [
        "channel",
        "requiredClientVersion",
        "timestamp",
        "version",
        "versions_hash"
      ],
      "type": "object"
    }
  },
  "properties": {
    "cachedPacks": {
      "items": {
        "$ref": "#/definitions/CachedUIPack"
      },
      "type": "array"
    },
    "version": {
      "type": "number"
    }
  },
  "required": [
    "cachedPacks",
    "version"
  ],
  "type": "object"
};
export type ValidateFunction<T> = ((data: unknown) => data is T) & Pick<Ajv.ValidateFunction, 'errors'>
export const isCacheFile = ajv.compile(CacheFileSchema) as ValidateFunction<CacheFile>;
export default function validate(value: unknown): CacheFile {
  if (isCacheFile(value)) {
    return value;
  } else {
    throw new Error(
      ajv.errorsText(isCacheFile.errors!.filter((e: any) => e.keyword !== 'if'), {dataVar: 'CacheFile'}) +
      '\n\n' +
      inspect(value),
    );
  }
}