$this->id, 'order_number' => $this->order_number, 'type' => $this->type, 'user_id' => $this->user_id, 'user' => $this->whenLoaded('user', fn() => new UserResource($this->user)), 'user_dependent_id' => $this->user_dependent_id, 'user_dependent' => $this->whenLoaded('userDependent', fn() => $this->userDependent ? [ 'id' => $this->userDependent->id, 'name' => $this->userDependent->name, 'kinship' => $this->userDependent->kinship, ] : null), 'is_for_dependent' => $this->user_dependent_id !== null, 'partner_agreement_id' => $this->partner_agreement_id, 'partner_agreement' => $this->whenLoaded('partnerAgreement', fn() => new PartnerAgreementResource($this->partnerAgreement)), 'partner_agreement_service_id' => $this->partner_agreement_service_id, 'partner_agreement_service' => $this->whenLoaded('partnerAgreementService', fn() => new PartnerAgreementServiceResource($this->partnerAgreementService)), 'exams' => $this->whenLoaded('exams', fn() => $this->exams->map(fn($exam) => [ 'id' => $exam->id, 'partner_agreement_service_id' => $exam->partner_agreement_service_id, 'name' => $exam->partnerAgreementService?->name, 'service_price' => $exam->service_price, ])), 'date' => $this->date?->format('Y-m-d'), 'time' => $this->time ? Carbon::parse($this->time)->format('H:i') : null, 'observations' => $this->observations, 'requested_at' => $this->requested_at?->format('Y-m-d H:i:s'), 'status' => $this->status, 'service_price' => $this->service_price, 'guide_issued_at' => $this->guide_issued_at?->format('Y-m-d H:i:s'), 'guide_valid_until' => $this->guide_valid_until?->format('Y-m-d'), 'can_issue_guide' => $this->resource instanceof \App\Models\Appointment ? app(\App\Services\AppointmentGuideService::class)->canIssue($this->resource) : false, 'auto_approved' => $this->auto_approved, 'approved_by_user_id' => $this->approved_by_user_id, 'approved_by_user' => $this->whenLoaded('approvedByUser', fn() => new UserResource($this->approvedByUser)), 'accepted_at' => $this->accepted_at?->format('Y-m-d H:i:s'), 'refused_at' => $this->refused_at?->format('Y-m-d H:i:s'), 'refused_by_user_id' => $this->refused_by_user_id, 'refusal_reason' => $this->refusal_reason, 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'), 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'), ]; } }