# Path: artman/tasks/task_base.py
# class TaskBase(Task):
# class EmptyTask(TaskBase):
#     def __init__(self, *args, **kwargs):
#     def log(self, msg, logger=artman_logger, level=logging.INFO):
#     def exec_command(self, args):
#     def execute(self):
#     def validate(self):
# 
# Path: artman/utils/task_utils.py
# def get_java_tool_path(toolkit_path, tool_name):
# def gapic_gen_task(toolkit_path, task_args):
# def run_gradle_task(toolkit_path, task_name, task_args=()):
# def api_full_name(api_name, api_version, organization_name):
# def is_output_gcloud(language, gapic_code_dir):
# def instantiate_tasks(task_class_list, inject):
# 
# Path: artman/utils/logger.py
# OUTPUT = 22
# SUCCESS = 25
# COLORS = {
#     'DEBUG': 'blue',
#     'INFO': 'cyan',
#     'OUTPUT': 'white',
#     'SUCCESS': 'green',
#     'WARNING': 'yellow',
#     'ERROR': 'red',
#     'CRITICAL': 'red,bold',
# }
# class Logger(logging.getLoggerClass()):
#     def __init__(self, name, level=logging.NOTSET):
#     def output(self, message, *args, **kwargs):
#     def success(self, message, *args, **kwargs):
# def setup_logging(level=logging.DEBUG):  # pragma: no cover
# def setup_logger(name, level, colors=COLORS,
#                  format_string="%(purple)s%(name)s> %(log_color)s%(message)s"):


import os
import subprocess
from artman.tasks import task_base
from artman.utils import task_utils
from artman.utils.logger import logger


class PhpFormatTask(task_base.TaskBase):
    def execute(self, gapic_code_dir):
        abs_code_dir = os.path.abspath(gapic_code_dir)
        logger.debug('Formatting file using php-cs-fixer in %s.' % abs_code_dir)
        subprocess.call(['php-cs-fixer', 'fix',
                         '--rules=@Symfony,-phpdoc_annotation_without_dot',
                         gapic_code_dir])
        # We require a second call to php-cs-fixer because instances of @type
        # have been converted to @var. We cannot disable this conversion in
        # the first call without affecting other aspects of the formatting.
        subprocess.call(['php-cs-fixer',
                         'fix',
                         '--rules={"phpdoc_no_alias_tag" : {"replacements" : '
                         '{"var" : "type"}}}',
                         gapic_code_dir])
        logger.debug('Formatting file using phpcbf in %s.' % abs_code_dir)
        subprocess.call(['phpcbf', '--standard=PSR2', '--no-patch',
                         gapic_code_dir])


_FORMAT_TASK_DICT = {
    'java': JavaFormatTask,
    'go': GoFormatTask,
    'php': PhpFormatTask,
}


def get_format_task(language):

# Path: artman/tasks/task_base.py
# class TaskBase(Task):
# class EmptyTask(TaskBase):
#     def __init__(self, *args, **kwargs):
#     def log(self, msg, logger=artman_logger, level=logging.INFO):
#     def exec_command(self, args):
#     def execute(self):
#     def validate(self):
# 
# Path: artman/utils/task_utils.py
# def get_java_tool_path(toolkit_path, tool_name):
# def gapic_gen_task(toolkit_path, task_args):
# def run_gradle_task(toolkit_path, task_name, task_args=()):
# def api_full_name(api_name, api_version, organization_name):
# def is_output_gcloud(language, gapic_code_dir):
# def instantiate_tasks(task_class_list, inject):
# 
# Path: artman/utils/logger.py
# OUTPUT = 22
# SUCCESS = 25
# COLORS = {
#     'DEBUG': 'blue',
#     'INFO': 'cyan',
#     'OUTPUT': 'white',
#     'SUCCESS': 'green',
#     'WARNING': 'yellow',
#     'ERROR': 'red',
#     'CRITICAL': 'red,bold',
# }
# class Logger(logging.getLoggerClass()):
#     def __init__(self, name, level=logging.NOTSET):
#     def output(self, message, *args, **kwargs):
#     def success(self, message, *args, **kwargs):
# def setup_logging(level=logging.DEBUG):  # pragma: no cover
# def setup_logger(name, level, colors=COLORS,
#                  format_string="%(purple)s%(name)s> %(log_color)s%(message)s"):


# Path: artman/tasks/format_tasks.py
import os
import subprocess
from artman.tasks import task_base
from artman.utils import task_utils
from artman.utils.logger import logger



class PhpFormatTask(task_base.TaskBase):
    def execute(self, gapic_code_dir):
        abs_code_dir = os.path.abspath(gapic_code_dir)
        logger.debug('Formatting file using php-cs-fixer in %s.' % abs_code_dir)
        subprocess.call(['php-cs-fixer', 'fix',
                         '--rules=@Symfony,-phpdoc_annotation_without_dot',
                         gapic_code_dir])
        # We require a second call to php-cs-fixer because instances of @type
        # have been converted to @var. We cannot disable this conversion in
        # the first call without affecting other aspects of the formatting.
        subprocess.call(['php-cs-fixer',
                         'fix',
                         '--rules={"phpdoc_no_alias_tag" : {"replacements" : '
                         '{"var" : "type"}}}',
                         gapic_code_dir])
        logger.debug('Formatting file using phpcbf in %s.' % abs_code_dir)
        subprocess.call(['phpcbf', '--standard=PSR2', '--no-patch',
                         gapic_code_dir])


_FORMAT_TASK_DICT = {
    'java': JavaFormatTask,
    'go': GoFormatTask,
    'php': PhpFormatTask,
}


def get_format_task(language):

    return _FORMAT_TASK_DICT.get(language, task_base.EmptyTask)