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

# ----------------------------------------------------------------------------------------------------------------------
# Author: Lalith Kumar Shiyam Sundar | Sebastian Gutschmayer
# Institution: Medical University of Vienna
# Research Group: Quantitative Imaging and Medical Physics (QIMP) Team
# Date: 04.07.2023
# Version: 0.1.0
#
# Description:
# This module shows predefined display messages for the falconz.
#
# Usage:
# The functions in this module can be imported and used in other modules within the falconz to show predefined display
# messages.
#
# ----------------------------------------------------------------------------------------------------------------------

import pyfiglet
import logging
from falconz import constants
from falconz import file_utilities


def logo():
    """
    Display FALCON logo
    :return:
    """
    print(' ')
    logo_color_code = constants.ANSI_VIOLET
    slogan_color_code = constants.ANSI_VIOLET
    result = logo_color_code + pyfiglet.figlet_format("FALCON 2.0", font="speed").rstrip() + "\033[0m"
    text = slogan_color_code + "A part of the ENHANCE community. Join us at https://enhance.pet to build the future " \
                               "of " \
                               "PET imaging together." + "\033[0m"
    print(result)
    print(text)
    print(' ')


def citation():
    """
    Display manuscript citation
    :return:
    """
    print(
        "Shiyam Sundar, L. K., Lassen, M. L., Muzik, O. (2023, June 8). Fully automated, fast motion correction of "
        "dynamic whole-body and total-body PET/CT Imaging Studies. Journal of Nuclear Medicine. "
        "https://jnm.snmjournals.org/content/early/2023/06/08/jnumed.122.265362 ")
    print(" Copyright 2022, Quantitative Imaging and Medical Physics Team, Medical University of Vienna")


def expectations():
    """
    Display expected modalities for PUMA. This is used to check if the user has provided the correct set of modalities for each tracer set.
    """
    # display the expected modalities
    print(f' Expected dimensions: {constants.EXPECTED_DIMENSIONS} | Allowed modalities: {constants.MODALITIES}')
    logging.info(f' Expected dimensions: {constants.EXPECTED_DIMENSIONS} | Allowed modalities: {constants.MODALITIES}')
    print(
        f"{constants.ANSI_ORANGE} Warning: Only 4D images will be considered in the analysis. {constants.ANSI_RESET}")

    warning_message = "Only 4D images will be considered in the analysis."
    logging.warning(warning_message)


def default_parameters(input_args):
    """
    Display default parameters for FALCON
    :return:
    """
    if input_args.reference_frame_index == -1:
        reference_frame_message = " Reference frame: Last frame"
    else:
        reference_frame_message = f" Reference frame: {input_args.reference_frame_index}"
    if input_args.multi_resolution_iterations.__eq__(constants.MULTI_RESOLUTION_SCHEME):
        multi_resolution_scheme_message = f" Multi-resolution scheme: {constants.MULTI_RESOLUTION_SCHEME}"
    else:
        multi_resolution_scheme_message = f" Multi-resolution scheme: {input_args.multi_resolution_iterations}"

    print(f' Registration type: {input_args.registration} | Shrink level: {constants.SHRINK_LEVEL} | '
          f'{multi_resolution_scheme_message} | {reference_frame_message}')


def derived_parameters(input_args):
    """
    Display derived parameters for FALCON
    :return:
    """
    if input_args.registration.__eq__('rigid'):
        num_jobs, avail_memory, avail_threads = file_utilities.get_number_of_possible_jobs(
            process_memory=c.MINIMUM_RAM_REQUIRED_RIGID,
            process_threads=c.MINIMUM_THREADS_REQUIRED_RIGID)
    elif input_args.registration.__eq__('affine'):
        num_jobs, avail_memory, avail_threads = file_utilities.get_number_of_possible_jobs(
            process_memory=c.MINIMUM_RAM_REQUIRED_AFFINE,
            process_threads=c.MINIMUM_THREADS_REQUIRED_AFFINE)
    elif input_args.registration.__eq__('deformable'):
        num_jobs, avail_memory, avail_threads = file_utilities.get_number_of_possible_jobs(
            process_memory=c.MINIMUM_RAM_REQUIRED_DEFORMABLE,
            process_threads=c.MINIMUM_THREADS_REQUIRED_DEFORMABLE)
    else:
        raise ValueError('Unsupported registration paradigm')

    print(f' Available memory: {avail_memory} GB | Available threads: {avail_threads} | Number of motion correction '
          f'done in parallel: {num_jobs}')
    logging.info(f' Available memory: {avail_memory} GB | Available threads: {avail_threads} | Number of motion '
                 f'correction done in parallel: {num_jobs}')
