<?php

declare(strict_types=1);

namespace OCA\Mitgliederverwaltung\Db;

use JsonSerializable;
use OCP\AppFramework\Db\Entity;

/**
 * Sale record entity mapping all columns from oc_mv_inventory_sales.
 *
 * Part of Issue #165 (Inventory Tracking).
 *
 * @method int|null getId()
 * @method void setId(int $id)
 * @method int|null getStockItemId()
 * @method void setStockItemId(?int $stockItemId)
 * @method int|null getVariantId()
 * @method void setVariantId(?int $variantId)
 * @method string getDate()
 * @method void setDate(string $date)
 * @method int getQuantity()
 * @method void setQuantity(int $quantity)
 * @method string getUnitPrice()
 * @method void setUnitPrice(string $unitPrice)
 * @method string getTotalPrice()
 * @method void setTotalPrice(string $totalPrice)
 * @method string|null getNotes()
 * @method void setNotes(?string $notes)
 * @method string getCreatedAt()
 * @method void setCreatedAt(string $createdAt)
 */
class SaleRecord extends Entity implements JsonSerializable {

    protected int $id = 0;
    protected ?int $stockItemId = null;
    protected ?int $variantId = null;
    protected string $date = '';
    protected int $quantity = 0;
    protected string $unitPrice = '0.00';
    protected string $totalPrice = '0.00';
    protected ?string $notes = null;
    protected string $createdAt = '';

    public function __construct() {
        $this->addType('id', 'integer');
        $this->addType('stockItemId', 'integer');
        $this->addType('variantId', 'integer');
        $this->addType('quantity', 'integer');
    }

    public function jsonSerialize(): array {
        return [
            'id' => $this->id,
            'stock_item_id' => $this->stockItemId,
            'variant_id' => $this->variantId,
            'date' => $this->date,
            'quantity' => $this->quantity,
            'unit_price' => $this->unitPrice,
            'total_price' => $this->totalPrice,
            'notes' => $this->notes,
            'created_at' => $this->createdAt,
        ];
    }
}
