defaults = {
    'apt': {
        'packages': {
            'python3-radicale': {},
        },
    },
    'backups': {
        'paths': {
            '/var/lib/radicale',
        },
    },
    'zfs': {
        'datasets': {
            'tank/radicale': {
                'mountpoint': '/var/lib/radicale',
                'needed_by': {
                    'directory:/var/lib/radicale/collections',
                    'pkg_apt:python3-radicale',
                },
            },
        },
    },
}


@metadata_reactor.provides(
    'nginx/vhosts/radicale',
)
def nginx(metadata):
    if not node.has_bundle('nginx'):
        raise DoNotRunAgain

    return {
        'nginx': {
            'vhosts': {
                'radicale': {
                    'domain': metadata.get('radicale/domain'),
                    'locations': {
                        '/': {
                            'target': 'http://[::1]:22050',
                            'auth': {
                                'file': '/etc/radicale/htpasswd',
                            },
                            'proxy_set_header': {
                                'X-Remote-User': '$remote_user',
                            },
                        },
                        '/.web/': {
                            'target': 'http://[::1]:22050',
                        }
                    },
                    'website_check_path': '/.web/',
                    'website_check_string': 'Radicale',
                },
            },
        },
    }
