import difflib

from salt.serializers import yaml


def failure(name, message):
    return {
        'name': name,
        'changes': {},
        'result': False,
        'comment': message,
    }


def present(name, chart_name, namespace, version=None, values=None,
            tiller_namespace='kube-system', tiller_host=None,
            kube_config=None, gce_service_token=None):
    tiller_args = {
        'tiller_namespace': tiller_namespace,
        'tiller_host': tiller_host,
        'kube_config': kube_config,
        'gce_service_token': gce_service_token,
    }
    exists = __salt__['helm.release_exists'](name, namespace, **tiller_args)
    if not exists:
        err = __salt__['helm.release_create'](
            name, chart_name, namespace, version, values, **tiller_args)
        if err:
            return failure(name, err)
        return {
            'name': name,
            'changes': {name: 'CREATED'},
            'result': True,
            'comment': 'Release "{}" was created'.format(name),
        }

    old_values = __salt__['helm.get_values'](name, **tiller_args)
    err = __salt__['helm.release_upgrade'](
        name, chart_name, namespace, version, values, **tiller_args)
    if err:
        return failure(name, err)

    new_values = __salt__['helm.get_values'](name, **tiller_args)
    if new_values == old_values:
        return {
            'name': name,
            'changes': {},
            'result': True,
            'comment': 'Release "{}" already exists'.format(name),
        }

    old_str = yaml.serialize(old_values, default_flow_style=False)
    new_str = yaml.serialize(new_values, default_flow_style=False)
    diff = difflib.unified_diff(
        old_str.split('\n'), new_str.split('\n'), lineterm='')
    return {
        'name': name,
        'changes': {'values': '\n'.join(diff)},
        'result': True,
        'comment': 'Release "{}" was updated'.format(name),
    }


def absent(name, namespace, tiller_namespace='kube-system', tiller_host=None,
           kube_config=None, gce_service_token=None):
    tiller_args = {
        'tiller_namespace': tiller_namespace,
        'tiller_host': tiller_host,
        'kube_config': kube_config,
        'gce_service_token': gce_service_token,
    }
    exists = __salt__['helm.release_exists'](name, namespace, **tiller_args)
    if not exists:
        return {
            'name': name,
            'changes': {},
            'result': True,
            'comment': 'Release "{}" doesn\'t exist'.format(name),
        }
    err = __salt__['helm.release_delete'](name, **tiller_args)
    if err:
        return failure(name, err)
    return {
        'name': name,
        'changes': {name: 'DELETED'},
        'result': True,
        'comment': 'Release "{}" was deleted'.format(name),
    }
