feat(validity-time): add ValidityTimeResource and integrate into catalog and ticket resources

This commit is contained in:
2026-08-06 16:13:29 -03:00
parent 7561ba756c
commit 20dd246cd8
9 changed files with 113 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Domains\Ticket\Resources;
use App\Domains\Ticket\Enums\ValidityTimeType;
use App\Domains\Ticket\Models\ValidityTime;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin ValidityTime */
class ValidityTimeResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
$fields = match ($this->type) {
ValidityTimeType::TimeWindow => [
'start_time' => $this->start_time,
'end_time' => $this->end_time,
],
ValidityTimeType::FixedWindow => [
'fixed_starts_at' => $this->fixed_starts_at,
'fixed_expires_at' => $this->fixed_expires_at,
],
};
return [
'id' => $this->id,
'type' => $this->type->value,
'is_valid' => $this->isValid(),
...array_filter($fields, fn (mixed $value): bool => $value !== null),
];
}
}