<commit_before><?php

/*
 * Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * For more information : <EMAIL>
 *
 */
declare(strict_types=1);

namespace Centreon\Domain\Monitoring;

use Centreon\Domain\Monitoring\Icon;
use Centreon\Domain\Monitoring\ResourceStatus;
use Centreon\Domain\Monitoring\ResourceSeverity;
use DateTime;
use CentreonDuration;

/**
 * Class representing a record of a resource in the repository.
 *
 * @package Centreon\Domain\Monitoring
 */
class Resource
{
    // Groups for serializing
    public const SERIALIZER_GROUP_MAIN = 'resource_main';
    public const SERIALIZER_GROUP_PARENT = 'resource_parent';

    // Types
    public const TYPE_SERVICE = 'service';
    public const TYPE_HOST = 'host';

    /**
     * @var string|null
     */
    private $id;

    /**
     * @var string|null
     */
    private $type;

    /**
     * @var string|null
     */
    private $name;

    /**
     * @var string|null
     */
    private $detailsUrl;

    /**
     * @var \Centreon\Domain\Monitoring\Icon|null
     */
    private $icon;

    /**
     * @var \Centreon\Domain\Monitoring\Resource|null
     */
    private $parent;

    /**
     * @var \Centreon\Domain\Monitoring\ResourceStatus|null
     */
    private $status;

    /**
     * @var bool
     */
    private $inDowntime = false;

    /**
     * @var bool
     */
    private $acknowledged = false;

    /**
     * @var string|null
     */
    private $downtimeEndpoint;

    /**
     * @var string|null
     */
    private $acknowledgementEndpoint;

    /**
     * @var string|null
     */
    private $statusGraphEndpoint;

    /**
     * @var string|null
     */
    private $performanceGraphEndpoint;

    /**
     * @var \Centreon\Domain\Monitoring\ResourceSeverity|null
     */
    private $severity;

    /**
     * @var int
     */
    private $impactedResourcesCount = 0;

    /**
     * @var string|null
     */
    private $actionUrl;

    /**
     * @var string|null
     */
    private $chartUrl;

    /**
     * @var \DateTime|null
     */
    private $lastStatusChange;

    /**
     * @var string|null
     */
    private $tries;

    /**
     * @var \DateTime|null
     */
    private $lastCheck;

    /**
     * @var string|null
     */
    private $information;

    /**
     * Get prepared list of groups for the context
     *
     * @return array
     */
    public static function contextGroupsForListing(): array
    {
        return [
            static::SERIALIZER_GROUP_MAIN,
            static::SERIALIZER_GROUP_PARENT,
            Icon::SERIALIZER_GROUP_MAIN,
            ResourceStatus::SERIALIZER_GROUP_MAIN,
            ResourceSeverity::SERIALIZER_GROUP_MAIN,
        ];
    }

    /**
     * @return string|null
     */
    public function getShortType(): ?string
    {
        return $this->type ? $this->type{0} : null;
    }

    /**
     * @return string|null
     */
    public function getDuration(): ?string
    {
        $result = null;

        if ($this->getLastCheck()) {
            $result = CentreonDuration::toString(time() - $this->getLastStatusChange()->getTimestamp());<commit_msg>fix(api): adjust the wrong check in Resource model (#8418)<commit_after><?php

/*
 * Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * For more information : <EMAIL>
 *
 */
declare(strict_types=1);

namespace Centreon\Domain\Monitoring;

use Centreon\Domain\Monitoring\Icon;
use Centreon\Domain\Monitoring\ResourceStatus;
use Centreon\Domain\Monitoring\ResourceSeverity;
use DateTime;
use CentreonDuration;

/**
 * Class representing a record of a resource in the repository.
 *
 * @package Centreon\Domain\Monitoring
 */
class Resource
{
    // Groups for serializing
    public const SERIALIZER_GROUP_MAIN = 'resource_main';
    public const SERIALIZER_GROUP_PARENT = 'resource_parent';

    // Types
    public const TYPE_SERVICE = 'service';
    public const TYPE_HOST = 'host';

    /**
     * @var string|null
     */
    private $id;

    /**
     * @var string|null
     */
    private $type;

    /**
     * @var string|null
     */
    private $name;

    /**
     * @var string|null
     */
    private $detailsUrl;

    /**
     * @var \Centreon\Domain\Monitoring\Icon|null
     */
    private $icon;

    /**
     * @var \Centreon\Domain\Monitoring\Resource|null
     */
    private $parent;

    /**
     * @var \Centreon\Domain\Monitoring\ResourceStatus|null
     */
    private $status;

    /**
     * @var bool
     */
    private $inDowntime = false;

    /**
     * @var bool
     */
    private $acknowledged = false;

    /**
     * @var string|null
     */
    private $downtimeEndpoint;

    /**
     * @var string|null
     */
    private $acknowledgementEndpoint;

    /**
     * @var string|null
     */
    private $statusGraphEndpoint;

    /**
     * @var string|null
     */
    private $performanceGraphEndpoint;

    /**
     * @var \Centreon\Domain\Monitoring\ResourceSeverity|null
     */
    private $severity;

    /**
     * @var int
     */
    private $impactedResourcesCount = 0;

    /**
     * @var string|null
     */
    private $actionUrl;

    /**
     * @var string|null
     */
    private $chartUrl;

    /**
     * @var \DateTime|null
     */
    private $lastStatusChange;

    /**
     * @var string|null
     */
    private $tries;

    /**
     * @var \DateTime|null
     */
    private $lastCheck;

    /**
     * @var string|null
     */
    private $information;

    /**
     * Get prepared list of groups for the context
     *
     * @return array
     */
    public static function contextGroupsForListing(): array
    {
        return [
            static::SERIALIZER_GROUP_MAIN,
            static::SERIALIZER_GROUP_PARENT,
            Icon::SERIALIZER_GROUP_MAIN,
            ResourceStatus::SERIALIZER_GROUP_MAIN,
            ResourceSeverity::SERIALIZER_GROUP_MAIN,
        ];
    }

    /**
     * @return string|null
     */
    public function getShortType(): ?string
    {
        return $this->type ? $this->type{0} : null;
    }

    /**
     * @return string|null
     */
    public function getDuration(): ?string
    {
        $result = null;

        if ($this->getLastStatusChange()) {
            $result = CentreonDuration::toString(time() - $this->getLastStatusChange()->getTimestamp());
{'fraction_non_alphanumeric': 0.1201832390191323, 'fraction_numerical': 0.004580975478307734, 'mean_word_length': 2.2203904555314535, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2008309', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2168, 'n_words': 539}