# -*- coding: utf-8 -*-
import argparse
from reporter import Logger
from reporter import report
from .themes import Theme


class Client(object):

    def init(self, args):
        """ Initialize the project with the template and directories """
        theme = Theme(args.project_name, args.theme)
        theme.init()

    def build(self, args):
        config_file = Theme.load_config()
        theme = Theme(config_file.get('PROJECT_NAME'),
                      config_file.get('THEME'))
        theme.build(config_file)

    def make(self, args):
        report("make!!")

    def clean(self, args):
        report("clean!!")


def main(argv=None):
    client = Client()
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers()

    init_parser = subparsers.add_parser('init')
    init_parser.add_argument('project_name', help="ProjectName, 'ProjectName'"
                                                  " or 'Project Name' ")
    init_parser.add_argument('-t', '--theme', type=str,
                             default='default', help="theme name")
    init_parser.set_defaults(func=client.init)

    build_parser = subparsers.add_parser('build')
    build_parser.set_defaults(func=client.build)

    make_parser = subparsers.add_parser('make')
    make_parser.set_defaults(func=client.make)

    clean_parser = subparsers.add_parser('clean')
    clean_parser.set_defaults(func=client.make)

    verbose = parser.add_mutually_exclusive_group()
    verbose.add_argument("-q", "--quiet", dest="verbose", action="store_false",
                         help="suppress non error messages",)

    verbose.add_argument("--verbose", dest="verbose",
                         help="Give more output. Option is additive, and " +
                         "can be used up to 3 times. (default: %(default)s)",
                         type=int, default=1, choices=[0, 1, 2, 3])

    args = parser.parse_args()

    if args is None:
        parser.print_help()
        return

    Logger(args)
    args.func(args)
