<?php


namespace Application\Service\Extension\Formatter;


use Application\Service\Extension\Helper\CheckLogicMessageFormatterHelper;
use Application\Service\Extension\Helper\UserHelper;
use Application\Service\Extension\Laminas;

class LogicErrorReplyFormatter extends BaseFormatter
{
    use CheckLogicMessageFormatterHelper;

    private static array $cache = [];
    public function __construct()
    {
        $this->registerHandler([
            'create_time' => 'createTimeHandler',
            'create_user' => 'createUserHandler'
        ]);
    }

    public function createTimeHandler($value, $item)
    {
        $this->formatterCheckType = Laminas::$serviceManager->itemPatientFormLogicError->fetchOne([
            'where' => ['id' => $item['error_id']]
        ])['error_type'];

        $q = Laminas::$serviceManager->itemPatientFormLogicErrorQuery->fetchOne([
            'columns' => ['content', 'platform', 'create_time', 'create_user_id', 'error_id'],
            'where' => ['id' => $item['id']]
        ]);

//        $this->formatterCreateUserId = $q['create_user_id'];
//        $this->formatterLogicErrorId = $q['error_id'];
//        $this->formatterPlatform = $q['platform'];
//        $this->formatterCreateTime = $q['create_time'];
//        $this->formatterItemId = $_POST['item_id'];

        return $this->setMessage('', $q['platform'] == 2)
            ->setErrorId($item['error_id'])
            ->setCreateUserId($q['create_user_id'])
            ->setCreateTime($q['create_time'])
            ->format();
    }

    public function createUserHandler()
    {
        return '';
    }
}