"""
Define custom exception.
"""


class MudderyError(Exception):
    """
    Define custom exception.
    
    MudderyError(<Error Message>) or
    MudderyError(<Error Code>, <Error Message>, data=<Error Data>)
    """
    def __init__(self, *args, **kwargs):
        self.code = -1
        self.data = None

        if len(args) == 0:
            super(MudderyError, self).__init__()
        elif len(args) == 1:
            arg = args[0]
            if type(arg) == int:
                super(MudderyError, self).__init__()
                self.code = arg
            elif type(arg) == str:
                super(MudderyError, self).__init__(args[0])
            else:
                super(MudderyError, self).__init__()
                self.data = arg
        else:
            super(MudderyError, self).__init__(args[1])
            self.code = args[0]
            self.data = kwargs.get("data")


class ERR(object):
    """
    Error codes.
    """
    no_error = 0

    unknown = -1

    internal = 10000

    no_api = 10001

    no_authentication = 10002

    no_permission = 10003

    missing_args = 10004

    no_table = 10005

    invalid_form = 10006

    upload_error = 10007

    import_data_error = 10008

    download_error = 10009

    export_data_error = 10010

    build_world_error = 10011

    upload_image_exist = 10012

    no_data = 10013

    invalid_input = 10014

    can_not_upgrade = 10015

    server_error = 10016

    inventory_error = 10017

    duplicate_key = 10018

    no_cache = 10019

    account_not_available = 10020

    password_too_simple = 10021

    can_not_find_command = 10022

    can_not_pass = 10023

    skill_in_cd = 10024

    can_not_buy = 10025

    died = 10026
