<?php
namespace Claromentis\Infocapture;

$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_4d707fab93bebb00bbe69e8159697c9" . "0" => base64_decode(""), "_f88e7f6a6d0d00" . "d08892b6a7bfe17" . "382" => base64_decode("U3VtbWFyaXplIHRoa" . "XM6IA=="), "_8fb81a354f1f2df" . "3ce6663dc9d343e8" . "3" => base64_decode("YXV0aG" . "9y"), "_7aefd482de7885" . "f4293c2926df28c" . "235" => base64_decode("anNvbl9lbm" . "NvZGU="), "_67a0d62" . "4aebcceb" . "0abd5ce5" . "6a53ff06" . "f" => base64_decode("ZGF0" . "ZQ=="), "_68e7faade226e8a404e43b206b4" . "99341" => base64_decode("c3RyaXBfdGFncw=" . "="), "_20da431906d41c76e04" . "ee049a4b6f42a" => base64_decode("Ly4uL3Byb21wdHMvaW5mb2NhcHR1cmVfc3VtbWFye" . "V9wcm9tcHQubWQ="), "object_i" . "d" => base64_decode("b2JqZ" . "WN0X2" . "lk"), "_401970bb3c5776ecf4bd1fc8849c5af" . "3" => base64_decode("e3tMQ" . "U5HVU" . "FHRX1" . "9"), "_38f12d8b8" . "c719a8ce0f" . "c2faefc225" . "f35" => base64_decode("YXJy" . "YXlf" . "bWFw"), "_db618ca8e79f97b4dff753e" . "c837942cf" => base64_decode("cHJva" . "mVjdF" . "9pZA=" . "="), "_644b798b19dd133ec9211fb" . "916df032b" => base64_decode("ZmlsZV9" . "nZXRfY2" . "9udGVud" . "HM="), "_eaffc5d7e" . "0ea1c84c4b" . "39f95d2e2f" . "c8d" => base64_decode("c3RyX3JlcGxhY2" . "U="), "_0690f750de625d57ad4442" . "bfa99b57df" => base64_decode("QUkgSW5mb2NhcHR1" . "cmUgU3VtbWFyeSBn" . "ZW5lcmF0aW9uIGZh" . "aWxlZDog"), "t" . "e" . "x" . "t" => base64_decode("dGV4d" . "A=="), "_e129d198f4910d90b7c2d5374ca96" . "2e3" => base64_decode("aGVscGRlc2su" . "YWkuc3VtbWFy" . "eS5lcnJvcg=="), "_f73dab6" . "06630b38" . "8645c4f7" . "d3fbb13b" . "b" => base64_decode("YXJyYXlfbWVyZ" . "2U="), "_715e469f808de377" . "0b824865fc09869b" => base64_decode("bm" . "90" . "ZX" . "M="), "_4298577e41894bcce23f896cd3" . "65aea4" => base64_decode("ZW4" . "="));
use Claromentis\Core\Ai\AbstractAiTextGenerationDialogPlugin;
use Claromentis\Core\Ai\AiPluginInterface;
use Claromentis\Core\Ai\Exceptions\AiException;
use Claromentis\Core\Ai\Parts\PartInterface;
use Claromentis\Core\Ai\Parts\TextPart;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\Security\SecurityContext;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use User;
use ClaText;
use Date;
use Throwable;






class AiIssueSummaryPlugin extends AbstractAiTextGenerationDialogPlugin
{
    use LoggerAwareTrait;
    private Api $api;
    private RestFormatter $formatter;
    private SecurityContext $securityContext;
    private Lmsg $lmsg;
    public function __construct(Api $api, RestFormatter $formatter, SecurityContext $securityContext, Lmsg $lmsg, ?LoggerInterface $logger = null)
    {
        $this->api = $api;
        $this->formatter = $formatter;
        $this->securityContext = $securityContext;
        $this->lmsg = $lmsg;
        $this->setLogger($logger ?? new NullLogger());
    }
    public function getType() : string
    {
        return AiPluginInterface::TYPE_TEXT_GENERATION;
    }
    public function getModule() : string
    {
        return InfocaptureApplication::NAME;
    }
    public function getLocalizations() : array
    {
        return [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4d707fab93bebb00bbe69e8" . "159697c90"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4d707fab93bebb00bbe69e81596" . "97c90"]];
    }
    public function getScriptUrl() : string
    {
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4d707fab93bebb00bbe69e8159" . "697c90"];
    }
    public function getSystemPromptParts(?string $languageCode = null, ?array $metadata = null) : array
    {
        $_ea94b42bce739d2b7107769e1b04306c = (int) ($metadata[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["object_i" . "d"]] ?? 0);
        $_47d202493f86e587c8454fae73657c90 = (int) ($metadata[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_db618ca8e79f97b4df" . "f753ec837942cf"]] ?? 0);
        $languageCode = $languageCode ?? $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_4298577e41894bcce23f896cd" . "365aea4"];
        try {
            $_13fd70a895d3350e21a9d4872e0260b5 = $this->api->getIssue($this->securityContext, $_ea94b42bce739d2b7107769e1b04306c);
            $_0a3f284de65e596869ef47aa9e91f906 = $this->api->getProject($this->securityContext, $_47d202493f86e587c8454fae73657c90);
            $this->api->loadHistoryForIssues($this->securityContext, [$_13fd70a895d3350e21a9d4872e0260b5]);
            $_69060fd98946c48b106c3cfed6f233a7 = $this->formatter->FormatIssue($this->securityContext, $_0a3f284de65e596869ef47aa9e91f906, $_13fd70a895d3350e21a9d4872e0260b5);
            $_bd7d21c5127e477f781627a8ae135437 = $_0a3f284de65e596869ef47aa9e91f906->UserHasPermission(HD_PERM_PRIVATE_NOTES, $_13fd70a895d3350e21a9d4872e0260b5);
            $_715e469f808de3770b824865fc09869b = $_13fd70a895d3350e21a9d4872e0260b5->GetNotes($_bd7d21c5127e477f781627a8ae135437);
            $data = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_f73dab6" . "06630b38" . "8645c4f7" . "d3fbb13b" . "b"]($_69060fd98946c48b106c3cfed6f233a7, [$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_715e469f808de3770b" . "824865fc09869b"] => $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_38f12d8b8c71" . "9a8ce0fc2faef" . "c225f35"](function ($_42f4f5c47629333345a44de2ac08c8b4) {
                return [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_67a0d624aebcceb0ab" . "d5ce56a53ff06f"] => (new Date($_42f4f5c47629333345a44de2ac08c8b4->date1))->getDate(DATE_FORMAT_CLA_DATETIME), $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_8fb81a354f1f2df3ce6663dc9" . "d343e83"] => User::GetNameById($_42f4f5c47629333345a44de2ac08c8b4->owner), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["tex" . "t"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_68e7faade226e8a404e43b206b49" . "9341"](ClaText::ProcessPlainBB($_42f4f5c47629333345a44de2ac08c8b4->note))];
            }, $_715e469f808de3770b824865fc09869b)]);
            $_e9027bfc36f7e4cd7275a5168ddf08d9 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_7aefd482de7885f4293c" . "2926df28c235"]($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
            $_222e093300bb683fde3139416df10122 = __DIR__ . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_20da431906d41c76e04" . "ee049a4b6f42a"];
            $_89d321620a139bc57d99351ab089ed33 = $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_644b798b19dd133ec9211fb9" . "16df032b"]($_222e093300bb683fde3139416df10122);
            $_89d321620a139bc57d99351ab089ed33 = $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_eaffc5d7e0ea1" . "c84c4b39f95d2e" . "2fc8d"]([$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_401970bb3c" . "5776ecf4bd1" . "fc8849c5af3"]], [$languageCode], $_89d321620a139bc57d99351ab089ed33);
            return [new TextPart($_89d321620a139bc57d99351ab089ed33, PartInterface::PART_ROLE_MODEL), new TextPart($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_f88e7f6a6d0d00d08892b6a7bfe173" . "82"] . $_e9027bfc36f7e4cd7275a5168ddf08d9, PartInterface::PART_ROLE_USER)];
        } catch (Throwable $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_0690f750" . "de625d57a" . "d4442bfa9" . "9b57df"] . $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage(), [$_fe441aa3ef350bfb1a1a1ad8520dd530]);
            throw new AiException(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_e129d198f4910d90b7c2d" . "5374ca962e3"]));
        }
    }
}