'''
Copyright 2016 Bio-Rad Laboratories, Inc.

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.

@author: Yuewei Sheng
@date:   August 22, 2016
'''

#=============================================================================
# Imports
#=============================================================================
from bioweb_api.apis.AbstractGetFunction import AbstractGetFunction
from bioweb_api.apis.parameters.ParameterFactory import ParameterFactory
from bioweb_api.apis.exp_def.ExpDefUtils import get_experiment_defintions, \
    update_experiment_definitions

#=============================================================================
# Class
#=============================================================================
class ExpDefGetFunction(AbstractGetFunction):

    #===========================================================================
    # Overridden Methods
    #===========================================================================
    @staticmethod
    def name():
        return "ExpDef"

    @staticmethod
    def summary():
        return "Retrieve experiment definitions."

    @classmethod
    def parameters(cls):
        cls.refresh_parameter = ParameterFactory.boolean("refresh",
                                                         "Refresh available " \
                                                         "run reports.",
                                                         default_value=False)
        parameters = [
                      cls.refresh_parameter,
                      ParameterFactory.format(),
                     ]
        return parameters

    @classmethod
    def process_request(cls, params_dict):
        if cls.refresh_parameter in params_dict and \
           params_dict[cls.refresh_parameter][0]:
            update_experiment_definitions()
            
        return get_experiment_defintions()

#===============================================================================
# Run Main
#===============================================================================
if __name__ == "__main__":
    function = ExpDefGetFunction()
    print function
