class Repository:
    def __init__(self, db):
        self.db = db

    def get_pending_rrns_today(self):
        sql = """
        SELECT r.TXN_NO, r.RRN_TWO,
               q.DCCB_CODE, q.BR_CODE,
               q.SRC_AC_NO, q.DEST_AC_NO,
               q.IFSC_CODE, q.TXN_AMT,
               q.BENEFICIARY_NAME, q.BENEFICIARY_ADD,
               q.REMITTER_NAME
        FROM NEFT_RTGS_TXN_RRN r
        JOIN NEFT_RTGS_TXN_QUEUE q ON q.TXN_NO = r.TXN_NO
        WHERE r.MARK_TYPE = 'N'
          AND q.TXN_DATE >= TRUNC(SYSDATE)
          AND q.TXN_DATE <  TRUNC(SYSDATE) + 1
        """
        return self.db.fetch_all(sql)   




    def insert_outward_log(self, d):
        sql = """
        INSERT INTO outward_neft_api_log (
            BANKCODE, TXNCODE, TXNIND,
            JRNL_ID, REF_NO, TRAN_DATE,
            TXN_AMT, RECVR_ACCT_NO, SENDER_ACCT_NO,
            RECIEVER_IFSC, SENDER_IFSC,
            SENDER_NAME, RECIEVER_NAME,
            BENEFICIARY_ADDRESS,
            SENDER_TO_RECIVER_INFO,
            MSG_TYPE
        ) VALUES (
            :bankcode, 'OUTWARD NEFT', 'DR',
            :jrnl_id, :ref_no, :tran_date,
            :txn_amt, :recv_ac, :send_ac,                 
            :ifsc, :sender_ifsc,
            :sender_name, :receiver_name,
            :beneficiary_address,
            :sender_info,
            'N06'
        )
        """
        self.db.execute(sql, d)

    def mark_processed(self, txn_no):
        self.db.execute(
            "UPDATE NEFT_RTGS_TXN_RRN SET MARK_TYPE='Y' WHERE TXN_NO=:txn",
            {"txn": txn_no}
        )
