|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Anaf\Responses\Efactura; |
| 6 | + |
| 7 | +use Anaf\Contracts\Response; |
| 8 | +use Anaf\Responses\Concerns\ArrayAccessible; |
| 9 | + |
| 10 | +/** |
| 11 | + * @implements Response<array{messages: array<int, array{creation_date: string, tax_identification_number: string, solicitation_id: string, details: string, type: string, id: string}>, count_messages_current_page: int, per_page: int, total_messages: int, total_pages: int, current_page: int, serial: string, tax_identification_numbers: string, title: string}> |
| 12 | + */ |
| 13 | +class CreatePaginatedMessagesResponse implements Response |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @use ArrayAccessible<array{messages: array<int, Message>, count_messages_current_page: int, per_page: int, total_messages: int, total_pages: int, current_page: int, serial: string, tax_identification_numbers: string, title: string}> |
| 17 | + */ |
| 18 | + use ArrayAccessible; |
| 19 | + |
| 20 | + /** |
| 21 | + * Creates a new CreateResponse instance. |
| 22 | + * |
| 23 | + * @param array<int, Message> $messages |
| 24 | + */ |
| 25 | + private function __construct( |
| 26 | + public readonly array $messages, |
| 27 | + public readonly string $serial, |
| 28 | + public readonly string $taxIdentificationNumbers, |
| 29 | + public readonly string $title, |
| 30 | + public readonly int $countMessagesCurrentPage, |
| 31 | + public readonly int $perPage, |
| 32 | + public readonly int $totalMessages, |
| 33 | + public readonly int $totalPages, |
| 34 | + public readonly int $currentPage, |
| 35 | + ) { |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Acts as static factory, and returns a new Response instance. |
| 40 | + * |
| 41 | + * @param array{mesaje: array<int, array{data_creare: string, cif: string, id_solicitare: string, detalii: string, tip: string, id: string}>, numar_inregistrari_in_pagina: int, numar_total_inregistrari_per_pagina: int, numar_total_inregistrari: int, numar_total_pagini: int, index_pagina_curenta:int, serial: string, cui: string, titlu: string} $attributes |
| 42 | + */ |
| 43 | + public static function from(array $attributes): self |
| 44 | + { |
| 45 | + $messages = array_map( |
| 46 | + static fn (array $result): Message => Message::from( |
| 47 | + $result |
| 48 | + ), |
| 49 | + $attributes['mesaje'], |
| 50 | + ); |
| 51 | + |
| 52 | + return new self( |
| 53 | + $messages, |
| 54 | + $attributes['serial'], |
| 55 | + $attributes['cui'], |
| 56 | + $attributes['titlu'], |
| 57 | + $attributes['numar_inregistrari_in_pagina'], |
| 58 | + $attributes['numar_total_inregistrari_per_pagina'], |
| 59 | + $attributes['numar_total_inregistrari'], |
| 60 | + $attributes['numar_total_pagini'], |
| 61 | + $attributes['index_pagina_curenta'], |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * {@inheritDoc} |
| 67 | + */ |
| 68 | + public function toArray(): array |
| 69 | + { |
| 70 | + return [ |
| 71 | + 'messages' => array_map( |
| 72 | + static fn (Message $result): array => $result->toArray(), |
| 73 | + $this->messages, |
| 74 | + ), |
| 75 | + 'count_messages_current_page' => $this->countMessagesCurrentPage, |
| 76 | + 'per_page' => $this->perPage, |
| 77 | + 'total_messages' => $this->totalMessages, |
| 78 | + 'total_pages' => $this->totalPages, |
| 79 | + 'current_page' => $this->currentPage, |
| 80 | + 'serial' => $this->serial, |
| 81 | + 'tax_identification_numbers' => $this->taxIdentificationNumbers, |
| 82 | + 'title' => $this->title, |
| 83 | + ]; |
| 84 | + } |
| 85 | +} |
0 commit comments