[self::STATUS_SUBMITTED], self::STATUS_SUBMITTED => [self::STATUS_APPROVED, self::STATUS_REJECTED], self::STATUS_APPROVED => [self::STATUS_PAID], self::STATUS_REJECTED => [], self::STATUS_PAID => [], ]; #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private ?int $id = null; #[ORM\Column(type: 'string', length: 36, unique: true)] private string $uuid; #[ORM\Column(name: 'entity_type', type: 'string', length: 10)] private string $entityType; #[ORM\Column(name: 'entity_id', type: 'integer')] private int $entityId; #[ORM\Column(name: 'insurance_id', type: 'integer')] private int $insuranceId; #[ORM\Column(name: 'insurance_kind', type: 'string', length: 15)] private string $insuranceKind; #[ORM\Column(name: 'total_claimed_rials', type: 'integer')] private int $totalClaimedRials = 0; #[ORM\Column(name: 'total_approved_rials', type: 'integer', nullable: true)] private ?int $totalApprovedRials = null; #[ORM\Column(name: 'total_paid_rials', type: 'integer', nullable: true)] private ?int $totalPaidRials = null; #[ORM\Column(type: 'string', length: 15)] private string $status = self::STATUS_PENDING; #[ORM\Column(name: 'reject_reason', type: 'text', nullable: true)] private ?string $rejectReason = null; /** شماره پرونده/پیگیری نزد بیمه‌گر — هنگام ارسال وارد می‌شود. */ #[ORM\Column(name: 'tracking_number', type: 'string', length: 60, nullable: true)] private ?string $trackingNumber = null; #[ORM\Column(name: 'submitted_at', type: 'integer', nullable: true)] private ?int $submittedAt = null; #[ORM\Column(name: 'settled_at', type: 'integer', nullable: true)] private ?int $settledAt = null; #[ORM\Column(name: 'created_at', type: 'integer')] private int $createdAt; #[ORM\Column(name: 'updated_at', type: 'integer')] private int $updatedAt; #[ORM\OneToMany(targetEntity: ClaimItem::class, mappedBy: 'claim', cascade: ['persist', 'remove'], orphanRemoval: true)] private Collection $items; public function __construct(string $entityType, int $entityId, int $insuranceId, string $insuranceKind) { $this->uuid = Uuid::v4()->toRfc4122(); $this->entityType = $entityType; $this->entityId = $entityId; $this->insuranceId = $insuranceId; $this->insuranceKind = $insuranceKind; $this->createdAt = time(); $this->updatedAt = time(); $this->items = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getUuid(): string { return $this->uuid; } public function getEntityType(): string { return $this->entityType; } public function getEntityId(): int { return $this->entityId; } public function getInsuranceId(): int { return $this->insuranceId; } public function getInsuranceKind(): string { return $this->insuranceKind; } public function getStatus(): string { return $this->status; } public function getTotalClaimedRials(): int { return $this->totalClaimedRials; } public function getTotalApprovedRials(): ?int { return $this->totalApprovedRials; } public function getTotalPaidRials(): ?int { return $this->totalPaidRials; } /** @return Collection */ public function getItems(): Collection { return $this->items; } public function addItem(ClaimItem $item): self { $this->items->add($item); $this->totalClaimedRials += $item->getClaimedRials(); $this->updatedAt = time(); return $this; } public function canTransitionTo(string $status): bool { return in_array($status, self::TRANSITIONS[$this->status] ?? [], true); } /** * انتقال‌های مجاز از وضعیت فعلی. پنل دکمه‌ها را از همین می‌سازد تا فهرست * مجاز فقط یک‌جا تعریف شده باشد. * * @return string[] */ public function allowedTransitions(): array { return self::transitionsFrom($this->status); } /** * همان جدول انتقال، برای مسیرهایی که ردیف خام (array hydration) دارند و * موجودیت را هیدریت نمی‌کنند. * * @return string[] */ public static function transitionsFrom(string $status): array { return self::TRANSITIONS[$status] ?? []; } public function getTrackingNumber(): ?string { return $this->trackingNumber; } public function getRejectReason(): ?string { return $this->rejectReason; } public function getSubmittedAt(): ?int { return $this->submittedAt; } public function getSettledAt(): ?int { return $this->settledAt; } public function getCreatedAt(): int { return $this->createdAt; } public function setTrackingNumber(?string $v): self { $this->trackingNumber = $v !== null && trim($v) !== '' ? trim($v) : null; $this->updatedAt = time(); return $this; } public function submit(): void { $this->status = self::STATUS_SUBMITTED; $this->submittedAt = time(); $this->updatedAt = time(); } public function approve(?int $approvedRials = null): void { $this->status = self::STATUS_APPROVED; $this->totalApprovedRials = $approvedRials ?? $this->totalClaimedRials; $this->updatedAt = time(); } public function reject(string $reason): void { $this->status = self::STATUS_REJECTED; $this->rejectReason = $reason; $this->settledAt = time(); $this->updatedAt = time(); } public function pay(?int $paidRials = null): void { $this->status = self::STATUS_PAID; $this->totalPaidRials = $paidRials ?? $this->totalApprovedRials ?? $this->totalClaimedRials; $this->settledAt = time(); $this->updatedAt = time(); } public function toArray(): array { return [ 'uuid' => $this->uuid, 'entity_type' => $this->entityType, 'entity_id' => $this->entityId, 'insurance_id' => $this->insuranceId, 'insurance_kind' => $this->insuranceKind, 'total_claimed_rials' => $this->totalClaimedRials, 'total_approved_rials' => $this->totalApprovedRials, 'total_paid_rials' => $this->totalPaidRials, 'status' => $this->status, 'reject_reason' => $this->rejectReason, 'tracking_number' => $this->trackingNumber, 'allowed_transitions' => $this->allowedTransitions(), 'submitted_at' => $this->submittedAt, 'settled_at' => $this->settledAt, 'created_at' => $this->createdAt, 'items' => array_map(fn(ClaimItem $i) => $i->toArray(), $this->items->toArray()), ]; } }