<?php

declare(strict_types=1);

namespace App\DataTransferObjects;

final readonly class InvestmentDistributionData
{
    public function __construct(
        public int $investmentPropertyId,
        public string $distributionPeriod,
        public float $totalRentalIncome,
        public float $managementFee,
        public float $maintenanceReserve,
        public float $netDistributable,
        public float $distributionPerShare,
        public string $status = 'pending',
    ) {}

    /**
     * Create from array
     *
     * @param  array<string, mixed>  $data
     */
    public static function fromArray(array $data): self
    {
        return new self(
            investmentPropertyId: (int) $data['investment_property_id'],
            distributionPeriod: $data['distribution_period'],
            totalRentalIncome: (float) $data['total_rental_income'],
            managementFee: (float) $data['management_fee'],
            maintenanceReserve: (float) $data['maintenance_reserve'],
            netDistributable: (float) $data['net_distributable'],
            distributionPerShare: (float) $data['distribution_per_share'],
            status: $data['status'] ?? 'pending',
        );
    }

    /**
     * Convert to array for model creation
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'investment_property_id' => $this->investmentPropertyId,
            'distribution_period' => $this->distributionPeriod,
            'total_rental_income' => $this->totalRentalIncome,
            'management_fee' => $this->managementFee,
            'maintenance_reserve' => $this->maintenanceReserve,
            'net_distributable' => $this->netDistributable,
            'distribution_per_share' => $this->distributionPerShare,
            'status' => $this->status,
        ];
    }
}
