"""
app_utils.py


"""
import epics
from typing import List
from app.config_logging import config_logging
from tools import globals


def get_dests_from_PVs() -> List[str]:
    """Gets list of destination names from PVs

    Returns:
        List[str]: String list of destination names
    """

    logger = config_logging()
    dest_names = []
    for i in range(15):
        pv = epics.PV(f"TPG:SYS0:1:DST{i:02d}:NAME")
        dest_name = pv.get()
        if dest_name:
            dest_names.append(dest_name)
    num_dests = len(dest_names)
    if num_dests == 0:
        logger.error("Unable to get destination names for PVs")
    if not verify_dest_PVs(dest_names):
        logger.warning("PV names don't match local - may be out of sync")
    return dest_names


def verify_dest_PVs(pv_list: List[str]) -> bool:
    """Checks if PVs have not been changed since last (human) check"""
    if globals.DEST_NAMES != pv_list:
        return False
    return True
