from py_jftech import read, where, to_tuple, write

from api import DatumType


@read
def get_base_datums(type: DatumType = None, crncy=None, risk=None, datum_ids=None, ticker=None):
    kwargs = {
        'rbd_id': to_tuple(datum_ids),
        'v_rbd_type': type,
        'v_rbd_crncy': crncy,
        'v_rbd_risk': risk,
        'v_rbd_bloomberg_ticker': to_tuple(ticker)
    }
    return f'''select rbd_id as id, rbd_datas as datas from robo_base_datum {where(**kwargs)}'''


@write
def update_datum(id, datas: str):
    return f'''update robo_base_datum set rbd_datas = '{datas}' where rbd_id = {id}'''
