# -*- coding: utf-8 -*-
"""
A subroutine to add FS block.
Requires the params structure as input.

Need to think of the reequired output (pulse sequence variable itself?)

@author: petrm
"""

#imports
from LF_scanner.pypulseq.make_gauss_pulse import make_gauss_pulse
from LF_scanner.pypulseq.make_trapezoid import make_trapezoid
from LF_scanner.pypulseq.calc_rf_center import calc_rf_center
from LF_scanner.pypulseq.calc_duration import calc_duration
import numpy as np

def FS_CHESS_block(params, scanner_parameters, gz90):
    #function creates CHESS saturation block with accompanied gx and gy spoiled gradients
    flip_fs = round(110 * np.pi / 180, 3) #TODO ad parameter to GUI
    params['B0'] = 1.5  # TODO add to GUI
    params['FS_sat_ppm'] = -3.30  # TODO add to GUI
    params['FS_pulse_duration'] = 8e-3  # TODO add to GUI
    FS_sat_frequency = params['B0'] * 1e-6 * params['FS_sat_ppm'] * params['gamma']


    rf_fs = make_gauss_pulse(flip_angle=flip_fs, system=scanner_parameters, duration=params['FS_pulse_duration'],
                             bandwidth=abs(params['BW_sat']), freq_offset=FS_sat_frequency)
    #TODO
    #rf_fs.phaseOffset=-2*pi*rf_fs.freqOffset*mr.calcRfCenter(rf_fs)
    gx_fs = make_trapezoid(channel="x", system=scanner_parameters, delay=calc_duration(rf_fs),
                           area= 4*gz90.area, rise_time=params['dG'])
    gy_fs = make_trapezoid(channel="y", system=scanner_parameters, delay=calc_duration(rf_fs),
                           area= 4*gz90.area, rise_time=params['dG'])

    return rf_fs, gx_fs, gy_fs



