<?php

namespace Shm\ShmPayment\TBankPayment;

class TBankReceiptItem
{

    public $name;
    private $priceKopecks = 0;
    public $quantity;

    public static function create()
    {
        return new self();
    }

    public function __construct() {}


    public function name($name)
    {
        $this->name = $name;
        return $this;
    }

    public function price($price)
    {
        $this->priceKopecks = TBankAmount::toKopecks($price);
        return $this;
    }

    public function quantity($quantity)
    {
        $this->quantity = $quantity;
        return $this;
    }

    public function amount(): int
    {
        return (int) round($this->priceKopecks * ($this->quantity ?? 0));
    }

    public function toArray()
    {
        return [
            "Name" => $this->name,
            "Price" => $this->priceKopecks,
            "Quantity" => $this->quantity,
            "Amount" => $this->amount(),
            "Tax" => TBankPayment::$terminalTaxRate,
        ];
    }
}
