<?php

declare(strict_types=1);

namespace App\DataTransferObjects;

final readonly class InvestmentPerformanceData
{
    public function __construct(
        public int $investmentPropertyId,
        public string $reportingPeriod,
        public float $occupancyRate,
        public float $averageDailyRate,
        public float $totalRevenue,
        public float $operatingExpenses,
        public float $netIncome,
        public float $propertyValue,
        public float $appreciationRate,
    ) {}

    /**
     * Create from array
     *
     * @param  array<string, mixed>  $data
     */
    public static function fromArray(array $data): self
    {
        return new self(
            investmentPropertyId: (int) $data['investment_property_id'],
            reportingPeriod: $data['reporting_period'],
            occupancyRate: (float) $data['occupancy_rate'],
            averageDailyRate: (float) $data['average_daily_rate'],
            totalRevenue: (float) $data['total_revenue'],
            operatingExpenses: (float) $data['operating_expenses'],
            netIncome: (float) $data['net_income'],
            propertyValue: (float) $data['property_value'],
            appreciationRate: (float) $data['appreciation_rate'],
        );
    }

    /**
     * Convert to array for model creation
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'investment_property_id' => $this->investmentPropertyId,
            'reporting_period' => $this->reportingPeriod,
            'occupancy_rate' => $this->occupancyRate,
            'average_daily_rate' => $this->averageDailyRate,
            'total_revenue' => $this->totalRevenue,
            'operating_expenses' => $this->operatingExpenses,
            'net_income' => $this->netIncome,
            'property_value' => $this->propertyValue,
            'appreciation_rate' => $this->appreciationRate,
        ];
    }
}
