# Copyright 2020 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module holds archive API calls for version 1 of the Timesketch API."""

from __future__ import unicode_literals

import datetime
import io
import json
import logging
import zipfile

import opensearchpy

from flask import abort
from flask import current_app
from flask import jsonify
from flask import request
from flask import send_file
from flask_login import current_user
from flask_login import login_required
from flask_restful import Resource

import pandas as pd

from timesketch import version
from timesketch.api.v1 import export
from timesketch.api.v1 import resources
from timesketch.api.v1 import utils
from timesketch.lib.definitions import HTTP_STATUS_CODE_BAD_REQUEST
from timesketch.lib.definitions import HTTP_STATUS_CODE_FORBIDDEN
from timesketch.lib.definitions import HTTP_STATUS_CODE_NOT_FOUND
from timesketch.lib.definitions import HTTP_STATUS_CODE_OK
from timesketch.lib.stories import manager as story_export_manager
from timesketch.models.sketch import Event
from timesketch.models.sketch import Sketch


logger = logging.getLogger('timesketch.api_archive')


class SketchArchiveResource(resources.ResourceMixin, Resource):
    """Resource to archive a sketch."""

    DEFAULT_QUERY_FILTER = {
        'size': 10000,
        'terminate_after': 10000
    }

    def __init__(self, **kwargs):