#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# System modules
from astropy.time import Time
import json

# Custom modules
from devices import tel, foc, rot
from devices import dom, lamp, light
from devices import cam, cab
from utils.logger import log

from config.constants import frame_number, dir_number
from config.constants import frame_type, dir_type
from config.constants import imagetyp, dateobs

offset = tel.offset
camall = cam.all
domaz = dom.azimuth
domop = dom.open
dommov = dom.is_moving
dompark = dom.is_parked
#basic = cab.basic()

now = Time.now()

#####################
##### Init page #####
#####################

init_panel = {
    
    "Telescope status": {
        "status": tel.park,
        "cover": tel.cover,
    },
    
    "Telescope offsets": {
    "zd": offset[0],
        "az": offset[1],
        "rot": rot.position,
    },

    "Dome": {
        "az": dom.azimuth,
        "open": dom.open,
        "moving": dommov,
        "parked": dompark,
    }
    
}    

########################
##### Control page #####
########################

control_panel = {
    
    "Dome": {    
        "slaved": dom.slave,
        "moving": dommov,
        "parked": dompark,
        "az": domaz,
        "open": domop,
#        "position": foc.position,
        "lamp": lamp.state,
        "light": light.state,
    }
    
}


dumps = {
    "init": init_panel,
    "control": control_panel
}

print(json.dumps(dumps, indent=4))

log.debug(f"Total elapsed time: {(Time.now()-now).sec :.2f}s")
