<?php

namespace App\Billing\Entity;

use App\Billing\Repository\ClaimItemRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ClaimItemRepository::class)]
#[ORM\Table(name: 'claim_items')]
#[ORM\Index(columns: ['invoice_item_id'], name: 'idx_claim_item_invoice_item')]
class ClaimItem
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Claim::class, inversedBy: 'items')]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Claim $claim;

    #[ORM\Column(name: 'invoice_item_id', type: 'integer')]
    private int $invoiceItemId;

    #[ORM\Column(name: 'claimed_rials', type: 'integer')]
    private int $claimedRials;

    #[ORM\Column(name: 'approved_rials', type: 'integer', nullable: true)]
    private ?int $approvedRials = null;

    public function __construct(Claim $claim, int $invoiceItemId, int $claimedRials)
    {
        $this->claim         = $claim;
        $this->invoiceItemId = $invoiceItemId;
        $this->claimedRials  = $claimedRials;
    }

    public function getId(): ?int            { return $this->id; }
    public function getInvoiceItemId(): int  { return $this->invoiceItemId; }
    public function getClaimedRials(): int   { return $this->claimedRials; }
    public function getApprovedRials(): ?int { return $this->approvedRials; }

    public function toArray(): array
    {
        return [
            'invoice_item_id' => $this->invoiceItemId,
            'claimed_rials'   => $this->claimedRials,
            'approved_rials'  => $this->approvedRials,
        ];
    }
}
