<?php

declare(strict_types=1);

namespace App\Services\TomTool;

use App\Utils\Tools;

final class TgSendFormat
{
    
    public $sTitleEmoji;
    public $sTitle;
    public $aContent;
    
    public function typeA ()
    {
        $sStr = '';
        
        $sStr .= "\n\n".$this->sTitleEmoji;
        
        $sStr .= "\n\n".$this->sTitle;
        
        foreach ($this->aContent as $v) {
//            echo "失联客机";
            $sStr .= "\n\n".$v[0]."：".$v[1];
        }
        
        return $sStr;
        
    }
    
    public function rowAdd($sName, $iFlowToday, $iUseWidth, $iMaxWidth, $iLimitDay = false, $sMemo = false) {
        
        $iUseWidth = Tools::flowToGB($iUseWidth);
        $iMaxWidth = Tools::flowToGB($iMaxWidth);
        $iFlowToday = Tools::flowToGB($iFlowToday);
        
        if ($iMaxWidth <= 0) {
            $sFlowRate = 0;
        } else {
            $sFlowRate = number_format($iUseWidth / $iMaxWidth * 100, 0, '.', '');
        }
            
        if ($sFlowRate > 70) {
            $sFlowEmoji = '🪫';
        } else {
            $sFlowEmoji = '🔋';
        }
        
//        $sFlowMix = $sFlowEmoji.' '.(100 - $sFlowRate)."%（".$iMaxWidth."g - ".$iUseWidth."g = ".$iMaxWidth - $iUseWidth."g）【 今：".$iFlowToday."g 】";
        $sFlowMix = $sFlowEmoji.' '.(100 - $sFlowRate)."%";
        
        $sFlowMix .= " [ ";
        
        if ($iMaxWidth != 0) {
            $sFlowMix .= "总".$iMaxWidth."g";
            $sFlowMix .= "，余".$iMaxWidth - $iUseWidth."g";
        }
        
        if ($iMaxWidth != 0) {
            $sFlowMix .= "，置".$iLimitDay."d";
        }
        
        if ($iMaxWidth != 0) {
            $sFlowMix .= "，今".$iFlowToday."g";
        } else {
            $sFlowMix .= "今".$iFlowToday."g";
        }
        
        $sFlowMix .= " ] ";
        
        if ($sMemo) {
            $sName .= "&".$sMemo;
        }
        
        $this->aContent[] = [$sName, $sFlowMix];
        
    }
    
}
