import json
import time
from prometheus_client import Gauge, Info
from global_conf import pipisa_length_metric, user_attempt_metric, user_last_attempt_metric

class user_info_struct: 
            user_id: str       
            user_fullname: str
            dick_size: int
            datetimes: str
            attemptsCount: int
            chat_id: int 
        


def metric_wrap(chatID:int, userName: str, length: int, attemptsCount: int):
    """Pass here chat ID, username, pipisa length and attempts count to wrap them into metric."""

    global pipisa_length_metric
    if not pipisa_length_metric:
        pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username'])
    global user_attempt_metric
    if not user_attempt_metric:
        user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username'])
    global user_last_attempt_metric
    if not user_last_attempt_metric:
        user_last_attempt_metric = Gauge('user_last_attempt_time', 'Last attempt time', labelnames=['ChatID', 'Username'])

    pipisa_length_metric.labels(chatID, userName).set(length) 
    user_attempt_metric.labels(chatID, userName).set(attemptsCount)
    user_last_attempt_metric.labels(chatID, userName).set(time.time_ns())