# Source code for api.cases.v2.category

    """Autogenerated API"""
    import requests
    from argus_cli.plugin import register_command

    @register_command(extending=('cases','v2','category'))
    def list_categories(id: list = None, shortName: list = None, offset: int = 0, limit: int = 25,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """List categories (INTERNAL)

        :param list id: List of category IDs to match
        :param list shortName: List of category shortnames to match
        :param int offset: Skip a number of results
        :param int limit: Maximum number of returned results
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :returns: {"offset": 630, "limit": 441, "responseCode": 200, "count": 71, "data": [{"id": 46, "name": "Aaron Johnson", "shortName": "About knowledge population exist beyond.", "description": "Certain purpose heavy wide animal may successful nation.", "localizedNames": {"additionalProperties": "Can night sound effort wait between expert arm."}, "createdTimestamp": 997616763, "createdByUser": {"id": 95, "customerID": 717, "userName": "gutierrezscott", "name": "Lori Franklin"}, "lastUpdatedTimestamp": 449378940, "lastUpdatedByUser": {"id": 278, "customerID": 811, "userName": "zachary40", "name": "Cynthia Jackson"}, "bindings": [{"id": "Success community key local site that.", "caseTypes": ["securityIncident"]}], "flags": ["DELETED"]}], "metaData": {"additionalProperties": {}}, "messages": [{"message": "Fact field avoid.", "messageTemplate": "Any treatment maintain throw court amount.", "field": "Action may account total.", "parameter": {}, "timestamp": 367111329}], "currentPage": 101, "size": 983}
        """
        from requests import get
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/cases/v2/category".format()
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'ArgusToolbelt/1.0'
        }

        if apiKey:
            headers["Argus-API-Key"] = apiKey
        elif authentication and isinstance(authentication, dict):
            headers.update(authentication)
        elif callable(authentication):
            headers.update(authentication(url))

        body = {}

        if offset:
            body.update({"offset": offset})

        if limit:
            body.update({"limit": limit})

        if id:
            body.update({"id": id})

        if shortName:
            body.update({"shortName": shortName})

        response = get(url, json=body if body else None, verify=verify, headers=headers)

        errors = []
        if response.status_code == 401:
            raise http.AuthenticationFailedException(response)
        elif response.status_code == 403:
            raise http.AccessDeniedException(response)
        elif response.status_code == 412:
            raise http.ValidationErrorException(response)
        elif response.status_code == 404:
            raise http.ObjectNotFoundException(response)

        return response.json() if json else response

    @register_command(extending=('cases','v2','category'))
    def create_category(name: str = None, shortName: str = None, description: str = None, localizedNames: dict = None, domain: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Add category (INTERNAL)

        :param str name: Descriptive name of category to add.  => [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]*
        :param str shortName: Shortname for the category. This value must be unique in domain.  => [a-zA-Z0-9_\-\.]*
        :param str description: Longer description of this category.  => [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]*
        :param dict localizedNames: Localized names. If not set, locales will fallback to main name.  => [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]*
        :param str domain: Name or ID of domain to create this category in.
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :returns: {"offset": 902, "limit": 955, "responseCode": 200, "count": 710, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Sometimes my city end.", "messageTemplate": "Direction hair professor kind memory free.", "field": "Week certain we southern PM its.", "parameter": {}, "timestamp": 363336645}], "currentPage": 947, "size": 774}
        """
        from requests import post
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/cases/v2/category".format()
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'ArgusToolbelt/1.0'
        }

        if apiKey:
            headers["Argus-API-Key"] = apiKey
        elif authentication and isinstance(authentication, dict):
            headers.update(authentication)
        elif callable(authentication):
            headers.update(authentication(url))

        body = {}

        if name:
            body.update({"name": name})

        if shortName:
            body.update({"shortName": shortName})

        if description:
            body.update({"description": description})

        if localizedNames:
            body.update({"localizedNames": localizedNames})

        if domain:
            body.update({"domain": domain})

        response = post(url, json=body if body else None, verify=verify, headers=headers)

        errors = []
        if response.status_code == 401:
            raise http.AuthenticationFailedException(response)
        elif response.status_code == 403:
            raise http.AccessDeniedException(response)
        elif response.status_code == 412:
            raise http.ValidationErrorException(response)
        elif response.status_code == 404:
            raise http.ObjectNotFoundException(response)

        return response.json() if json else response

    @register_command(extending=('cases','v2','category'))
    def search_categories(limit: int = None, offset: int = None, includeFlags: int = None, excludeFlags: int = None, subCriteria: list = None, id: list = None, shortName: list = None, sortBy: list = None, includeDeleted: bool = 'False', exclude: bool = 'False', required: bool = 'False',json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Search categories (INTERNAL)

        :param int limit: Set this value to set max number of results. By default, no restriction on result set size.
        :param int offset: Set this value to skip the first (offset) objects. By default, return result from first object.
        :param int includeFlags: Only include objects which have includeFlags set.
        :param int excludeFlags: Exclude objects which have excludeFlags set.
        :param list subCriteria:
        :param list id: Limit search to categories with the specified numeric ID`s.
        :param list shortName: Limit search to categories with the specified shortnames
        :param list sortBy: List of properties to sort by (prefix with "-" to sort descending).
        :param bool includeDeleted: Set to true to include deleted objects. By default, exclude deleted objects.
        :param bool exclude: Only relevant for subcriteria. If set to true, objects matching this subcriteria object will be excluded.
        :param bool required: Only relevant for subcriteria. If set to true, objects matching this subcriteria are required (AND-ed together with parent criteria).
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :returns: {"offset": 449, "limit": 671, "responseCode": 200, "count": 590, "data": [{"id": 534, "name": "Paige Conley", "shortName": "Find go successful cold head.", "description": "Catch power everything argue speak.", "localizedNames": {"additionalProperties": "Film story candidate should writer behind understand hot."}, "createdTimestamp": 1198994106, "createdByUser": {"id": 78, "customerID": 754, "userName": "johnporter", "name": "Kaylee Rogers"}, "lastUpdatedTimestamp": 978007281, "lastUpdatedByUser": {"id": 642, "customerID": 195, "userName": "petersentaylor", "name": "William Norton"}, "bindings": [{"id": "Friend book assume hot probably.", "caseTypes": ["change"]}], "flags": ["DELETED"]}], "metaData": {"additionalProperties": {}}, "messages": [{"message": "Result happy class very.", "messageTemplate": "Design four better section pay way month consumer.", "field": "Mrs serve town style rate accept.", "parameter": {}, "timestamp": 1285276925}], "currentPage": 452, "size": 634}
        """
        from requests import post
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/cases/v2/category/search".format()
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'ArgusToolbelt/1.0'
        }

        if apiKey:
            headers["Argus-API-Key"] = apiKey
        elif authentication and isinstance(authentication, dict):
            headers.update(authentication)
        elif callable(authentication):
            headers.update(authentication(url))

        body = {}

        if limit:
            body.update({"limit": limit})

        if offset:
            body.update({"offset": offset})

        if includeDeleted:
            body.update({"includeDeleted": includeDeleted})

        if includeFlags:
            body.update({"includeFlags": includeFlags})

        if excludeFlags:
            body.update({"excludeFlags": excludeFlags})

        if subCriteria:
            body.update({"subCriteria": subCriteria})

        if exclude:
            body.update({"exclude": exclude})

        if required:
            body.update({"required": required})

        if id:
            body.update({"id": id})

        if shortName:
            body.update({"shortName": shortName})

        if sortBy:
            body.update({"sortBy": sortBy})

        response = post(url, json=body if body else None, verify=verify, headers=headers)

        errors = []
        if response.status_code == 401:
            raise http.AuthenticationFailedException(response)
        elif response.status_code == 403:
            raise http.AccessDeniedException(response)
        elif response.status_code == 412:
            raise http.ValidationErrorException(response)
        elif response.status_code == 404:
            raise http.ObjectNotFoundException(response)

        return response.json() if json else response

    @register_command(extending=('cases','v2','category'))
    def get_category(id: str,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Fetch category (INTERNAL)

        :param str id: ID or shortname of category to fetch
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises ObjectNotFoundException: on 404
        :returns: {"offset": 992, "limit": 359, "responseCode": 200, "count": 964, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Herself Mr look perhaps too.", "messageTemplate": "Other half until as nice what week.", "field": "Management cover yourself base.", "parameter": {}, "timestamp": 1284074442}], "currentPage": 239, "size": 890}
        """
        from requests import get
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/cases/v2/category/{id}".format(id=id)
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'ArgusToolbelt/1.0'
        }

        if apiKey:
            headers["Argus-API-Key"] = apiKey
        elif authentication and isinstance(authentication, dict):
            headers.update(authentication)
        elif callable(authentication):
            headers.update(authentication(url))

        body = {}

        response = get(url, json=body if body else None, verify=verify, headers=headers)

        errors = []
        if response.status_code == 401:
            raise http.AuthenticationFailedException(response)
        elif response.status_code == 403:
            raise http.AccessDeniedException(response)
        elif response.status_code == 412:
            raise http.ValidationErrorException(response)
        elif response.status_code == 404:
            raise http.ObjectNotFoundException(response)

        return response.json() if json else response

    @register_command(extending=('cases','v2','category'))
    def update_category(id: str, name: str = None, shortName: str = None, description: str = None, localizedNames: dict = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Update category (INTERNAL)

        :param str id: ID or shortname of category to update
        :param str name: If set, change the descriptive name for this category.  => [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]*
        :param str shortName: If set, change the shortname name for this category. WARNING: This may affect scripts using the category name.  => [a-zA-Z0-9_\-\.]*
        :param str description: If set, change the long description for this category.  => [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]*
        :param dict localizedNames: Set localized names to override name for specified language. Only specified languages are changed.  => [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]*
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises ObjectNotFoundException: on 404
        :returns: {"offset": 401, "limit": 914, "responseCode": 200, "count": 108, "metaData": {"additionalProperties": {}}, "messages": [{"message": "American there free guy south other.", "messageTemplate": "Candidate practice situation check against section.", "field": "First hold large citizen single.", "parameter": {}, "timestamp": 854104626}], "currentPage": 71, "size": 328}
        """
        from requests import put
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/cases/v2/category/{id}".format(id=id)
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'ArgusToolbelt/1.0'
        }

        if apiKey:
            headers["Argus-API-Key"] = apiKey
        elif authentication and isinstance(authentication, dict):
            headers.update(authentication)
        elif callable(authentication):
            headers.update(authentication(url))

        body = {}

        if name:
            body.update({"name": name})

        if shortName:
            body.update({"shortName": shortName})

        if description:
            body.update({"description": description})

        if localizedNames:
            body.update({"localizedNames": localizedNames})

        response = put(url, json=body if body else None, verify=verify, headers=headers)

        errors = []
        if response.status_code == 401:
            raise http.AuthenticationFailedException(response)
        elif response.status_code == 403:
            raise http.AccessDeniedException(response)
        elif response.status_code == 412:
            raise http.ValidationErrorException(response)
        elif response.status_code == 404:
            raise http.ObjectNotFoundException(response)

        return response.json() if json else response

    @register_command(extending=('cases','v2','category'))
    def delete_category(id: str,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Delete category (INTERNAL)

        :param str id: ID or shortname of category to delete
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises ObjectNotFoundException: on 404
        :returns: {"offset": 707, "limit": 67, "responseCode": 200, "count": 363, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Argue choose stock information evening box central.", "messageTemplate": "Student boy budget final age audience fear particular.", "field": "Race sometimes art identify capital if time.", "parameter": {}, "timestamp": 1496472723}], "currentPage": 651, "size": 803}
        """
        from requests import delete
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/cases/v2/category/{id}".format(id=id)
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'ArgusToolbelt/1.0'
        }

        if apiKey:
            headers["Argus-API-Key"] = apiKey
        elif authentication and isinstance(authentication, dict):
            headers.update(authentication)
        elif callable(authentication):
            headers.update(authentication(url))

        body = {}

        response = delete(url, json=body if body else None, verify=verify, headers=headers)

        errors = []
        if response.status_code == 401:
            raise http.AuthenticationFailedException(response)
        elif response.status_code == 403:
            raise http.AccessDeniedException(response)
        elif response.status_code == 412:
            raise http.ValidationErrorException(response)
        elif response.status_code == 404:
            raise http.ObjectNotFoundException(response)

        return response.json() if json else response