Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Generated\App\Bsky\Labeler;
4
5use Carbon\Carbon;
6use SocialDept\AtpSchema\Data\Data;
7use SocialDept\AtpSchema\Generated\App\Bsky\Labeler\Defs\LabelerPolicies;
8use SocialDept\AtpSchema\Generated\Com\Atproto\Moderation\Defs\ReasonType;
9use SocialDept\AtpSchema\Generated\Com\Atproto\Moderation\Defs\SubjectType;
10use SocialDept\AtpSchema\Support\UnionHelper;
11
12/**
13 * GENERATED CODE - DO NOT EDIT
14 *
15 * Lexicon: app.bsky.labeler.service
16 * Type: record
17 */
18class Service extends Data
19{
20 /**
21 * @param array<ReasonType>|null $reasonTypes The set of report reason 'codes' which are in-scope for this service to review and action. These usually align to policy categories. If not defined (distinct from empty array), all reason types are allowed.
22 * @param array<SubjectType>|null $subjectTypes The set of subject types (account, record, etc) this service accepts reports on.
23 * @param array<string>|null $subjectCollections Set of record types (collection NSIDs) which can be reported to this service. If not defined (distinct from empty array), default is any record type.
24 */
25 public function __construct(
26 public readonly LabelerPolicies $policies,
27 public readonly Carbon $createdAt,
28 public readonly mixed $labels = null,
29 public readonly ?array $reasonTypes = null,
30 public readonly ?array $subjectTypes = null,
31 public readonly ?array $subjectCollections = null
32 ) {
33 }
34
35 /**
36 * Get the lexicon NSID for this data type.
37 *
38 * @return string
39 */
40 public static function getLexicon(): string
41 {
42 return 'app.bsky.labeler.service';
43 }
44
45
46 /**
47 * Create an instance from an array.
48 *
49 * @param array $data The data array
50 * @return static
51 */
52 public static function fromArray(array $data): static
53 {
54 return new static(
55 policies: LabelerPolicies::fromArray($data['policies']),
56 createdAt: Carbon::parse($data['createdAt']),
57 labels: isset($data['labels']) ? UnionHelper::validateOpenUnion($data['labels']) : null,
58 reasonTypes: isset($data['reasonTypes']) ? array_map(fn ($item) => ReasonType::fromArray($item), $data['reasonTypes']) : [],
59 subjectTypes: isset($data['subjectTypes']) ? array_map(fn ($item) => SubjectType::fromArray($item), $data['subjectTypes']) : [],
60 subjectCollections: $data['subjectCollections'] ?? null
61 );
62 }
63
64}