<?php
declare(strict_types=1);

namespace App\Core\DTO;

final class JournalEntryRequest
{
    public function __construct(
        public readonly string $entryDate,
        public readonly string $descriptionAr,
        public readonly array $lines,
        public readonly ?string $descriptionEn = null,
        public readonly ?string $referenceType = null,
        public readonly ?int $referenceId = null,
        public readonly ?string $referenceNumber = null,
        public readonly ?string $sourceModule = null,
        public readonly bool $isAutoGenerated = false,
        public readonly bool $autoPost = false,
    ) {}

    public function toHeaderArray(): array
    {
        return array_filter([
            'entry_date' => $this->entryDate,
            'description_ar' => $this->descriptionAr,
            'description_en' => $this->descriptionEn,
            'reference_type' => $this->referenceType,
            'reference_id' => $this->referenceId,
            'reference_number' => $this->referenceNumber,
            'source_module' => $this->sourceModule,
            'is_auto_generated' => $this->isAutoGenerated ? 1 : 0,
        ], fn($v) => $v !== null);
    }

    public function toLines(): array
    {
        return $this->lines;
    }
}
