Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
GroupOlxDashboardData
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
13
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 xmlValidLabel
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 lastGeneratedAtLabel
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 xmlSizeLabel
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 generationDurationLabel
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 hasErrors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Data;
6
7use Carbon\CarbonInterface;
8
9/**
10 * Painel Publishing — Grupo OLX (VRSync). Sem gráficos.
11 */
12final readonly class GroupOlxDashboardData
13{
14    /**
15     * @param  list<string>  $errors
16     */
17    public function __construct(
18        public bool $xmlValid,
19        public ?CarbonInterface $lastGeneratedAt,
20        public int $listingCount,
21        public array $errors,
22        public string $publicUrl,
23        public ?int $xmlSizeBytes,
24        public ?int $generationDurationMs,
25        public bool $available,
26        public ?string $storageVersion = null,
27        public ?string $contentHash = null,
28    ) {}
29
30    public function xmlValidLabel(): string
31    {
32        if (! $this->available) {
33            return 'Indisponível';
34        }
35
36        return $this->xmlValid ? 'Válido' : 'Inválido';
37    }
38
39    public function lastGeneratedAtLabel(): ?string
40    {
41        return $this->lastGeneratedAt
42            ?->timezone(config('app.timezone'))
43            ->format('d/m/Y H:i');
44    }
45
46    public function xmlSizeLabel(): string
47    {
48        if ($this->xmlSizeBytes === null) {
49            return '—';
50        }
51
52        $bytes = $this->xmlSizeBytes;
53
54        if ($bytes < 1024) {
55            return $bytes.' B';
56        }
57
58        if ($bytes < 1024 * 1024) {
59            return number_format($bytes / 1024, 1, ',', '.').' KB';
60        }
61
62        return number_format($bytes / (1024 * 1024), 2, ',', '.').' MB';
63    }
64
65    public function generationDurationLabel(): string
66    {
67        if ($this->generationDurationMs === null) {
68            return '—';
69        }
70
71        if ($this->generationDurationMs < 1000) {
72            return $this->generationDurationMs.' ms';
73        }
74
75        return number_format($this->generationDurationMs / 1000, 2, ',', '.').' s';
76    }
77
78    public function hasErrors(): bool
79    {
80        return $this->errors !== [];
81    }
82}