from datetime import datetime


def _iardict_to_fil_header(iardict: dict) -> dict:
    """Build dict header from dict iar."""
    source_name = iardict["Source Name"]
    source_ra = iardict["Source RA (hhmmss.s)"]
    source_dec = iardict["Source DEC (ddmmss.s)"]
    # ref_dm = iardict["Reference DM"]
    # pul_period = iardict["Pulsar Period"]
    # high_freq = iardict["Highest Observation Frequency (MHz)"]
    telescope_id = int(iardict["Telescope ID"])
    machine_id = int(iardict["Machine ID"])
    data_type = int(iardict["Data Type"])
    # observing_time = int(iardict["Observing Time (minutes)"])
    # gain = iardict["Gain (dB)"]
    # bandwidth = int(iardict["Total Bandwith (MHz)"])
    avg_data = int(iardict["Average Data"])
    sub_bands = int(iardict["Sub Bands"])

    # ---- ROACH ----
    # values
    fft_pts = 128
    adc_clk = 200e6
    #  parameters
    tsamp = avg_data * fft_pts / adc_clk
    f_off = adc_clk / fft_pts * 1e-6

    time_now = datetime.now().strftime("_%Y%m%d_%H%M%S")

    # tsamp = 1e6 / float(bandwidth) * avg_data
    rawdatafile = f"ds{avg_data}_{source_name}{time_now}.fil"

    return {
        "telescope_id": telescope_id,
        "machine_id": machine_id,
        "data_type": data_type,
        "rawdatafile": rawdatafile,
        "source_name": source_name,
        "az_start": 0.0,
        "za_start": 0.0,
        "src_raj": source_ra,
        "src_dej": source_dec,
        "tstart": 0.0,
        "tsamp": tsamp,
        "fch1": 0.0,
        "foff": f_off,
        "nchans": sub_bands,
        "nifs": 1,
        "ibeam": 1,
        "nbeams": 1,
    }