"""
Manipulation with the devices to connect.
File: devices.py
Author: Radek Krejci <rkrejci@cesnet.cz>
"""

import json
import os
import errno

from liberouterapi import auth
from flask import request

from .inventory import INVENTORY, inventory_check
from .error import NetopeerException

__DEVICES_EMPTY = '{"device":[]}'


def __devices_init():
	return json.loads(__DEVICES_EMPTY)

def __devices_inv_load(path):
	devicesinv_path = os.path.join(path, 'devices.json')
	try:
		with open(devicesinv_path, 'r') as devices_file:
			devices = json.load(devices_file)
	except OSError as e:
		if e.errno == errno.ENOENT:
			devices = __devices_init()
		else:
			raise NetopeerException('Unable to use user\'s devices inventory ' + devicesinv_path + ' (' + str(e) + ').')
	except ValueError:
		devices = __devices_init()

	return devices

def __devices_inv_save(path, devices):
	devicesinv_path = os.path.join(path, 'devices.json')

	#store the list
	try:
		with open(devicesinv_path, 'w') as devices_file:
			json.dump(devices, devices_file)
	except Exception:
		pass

	return devices

@auth.required()
def devices_list():
	session = auth.lookup(request.headers.get('lgui-Authorization', None))
	user = session['user']
	path = os.path.join(INVENTORY, user.username)

	inventory_check(path)
	devices = __devices_inv_load(path)

	for dev in devices['device']:
		if 'password' in dev:
			del dev['password']

	return(json.dumps(devices['device']))

@auth.required()
def devices_add():
	session = auth.lookup(request.headers.get('lgui-Authorization', None))
	user = session['user']
	path = os.path.join(INVENTORY, user.username)

	device = request.get_json()
	if not device or not device['id']:
		raise NetopeerException('Invalid device remove request.')

	devices = __devices_inv_load(path)
	for dev in devices['device']:
		if dev['id'] == device['id']:
			return (json.dumps({'success': False}))

	device_json = {'id':device['id'],
		'name':device['name'],
		'hostname':device['hostname'],
		'port':device['port'],
		'autoconnect':device['autoconnect'],
		'username':device['username']}
	if 'password' in device and device['password']:
		device_json['password'] = device['password']
	devices['device'].append(device_json)

	#store the list
	__devices_inv_save(path, devices)

	return(json.dumps({'success': True}))

@auth.required()
def devices_rm():
	session = auth.lookup(request.headers.get('lgui-Authorization', None))
	user = session['user']
	path = os.path.join(INVENTORY, user.username)

	rm_id = request.get_json()['id']
	if not rm_id:
		raise NetopeerException('Invalid device remove request.')

	devices = __devices_inv_load(path)
	for i in range(len(devices['device'])):
		device = devices['device'][i]
		if device['id'] == rm_id:
			devices['device'].pop(i)
			device = None
			break

	if device:
		# device not in inventory
		return (json.dumps({'success': False}))

	# update the inventory database
	__devices_inv_save(path, devices)

	return(json.dumps({'success': True}))

def devices_get(device_id, username):
	path = os.path.join(INVENTORY, username)
	devices = __devices_inv_load(path)

	for i in range(len(devices['device'])):
		device = devices['device'][i]
		if device['id'] == device_id:
			return device

	return None


def devices_replace(device_id, username, device):
	path = os.path.join(INVENTORY, username)
	devices = __devices_inv_load(path)

	for i in range(len(devices['device'])):
		if devices['device'][i]['id'] == device_id:
			devices['device'][i] = device
			break

	# update the inventory database
	__devices_inv_save(path, devices)
