o
    	i3	                     @  s   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 e
eZdZddd	ZdddZdddZ		ddddZdddZdS )    )annotationsN)AnyDictListOptional)get_connectiona  
CREATE TABLE IF NOT EXISTS `stt_pipeline_bid_config` (
    `bid`               VARCHAR(100) NOT NULL,
    `enabled`           TINYINT(1)   NOT NULL DEFAULT 0,
    `raw_calls_id_col`  VARCHAR(100) NOT NULL DEFAULT 'id',
    `raw_calls_url_col` VARCHAR(100) NOT NULL DEFAULT 'recording_url',
    `batch_size`        INT          NOT NULL DEFAULT 10,
    `poll_interval_s`   INT          NOT NULL DEFAULT 30,
    `notes`             TEXT         NULL,
    `created_at`        DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`        DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`bid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
returnNonec               	   C  sn   t  *} |  }|t W d    n1 sw   Y  W d    d S W d    d S 1 s0w   Y  d S )N)r   cursorexecute_CREATE_TABLE_SQLconncur r   D/home/aiteam/pcaa-dev/call-proccessing/stt_pipeline/db/bid_config.pyensure_table   s   
"r   List[Dict[str, Any]]c               	   C  x   t  /} |  }|d | pg W  d    W  d    S 1 s%w   Y  W d    d S 1 s5w   Y  d S )Nz2SELECT * FROM stt_pipeline_bid_config ORDER BY bidr   r
   r   fetchallr   r   r   r   get_all_bid_configs   s   


"r   c               	   C  r   )NzDSELECT * FROM stt_pipeline_bid_config WHERE enabled = 1 ORDER BY bidr   r   r   r   r   get_enabled_bids%   s   

"r   idrecording_urlbidstrid_colurl_colc              	   C  sv   t  .}| }|d| ||f W d   n1 sw   Y  W d   dS W d   dS 1 s4w   Y  dS )z?Insert a disabled row for this bid if it doesn't already exist.zuINSERT IGNORE INTO stt_pipeline_bid_config (bid, enabled, raw_calls_id_col, raw_calls_url_col) VALUES (%s, 0, %s, %s)N)r   r
   r   )r   r   r   r   r   r   r   r   ensure_bid_registered.   s   
"r   Optional[Dict[str, Any]]c              	   C  sx   t  /}| }|d| f | W  d    W  d    S 1 s%w   Y  W d    d S 1 s5w   Y  d S )Nz4SELECT * FROM stt_pipeline_bid_config WHERE bid = %s)r   r
   r   fetchone)r   r   r   r   r   r   get_bid_config>   s   
"r"   )r   r	   )r   r   )r   r   )r   r   r   r   r   r   r   r	   )r   r   r   r    )
__future__r   loggingtypingr   r   r   r   db.connectionr   	getLogger__name__loggerr   r   r   r   r   r"   r   r   r   r   <module>   s    



