<?php

declare(strict_types=1);

namespace App\DataTransferObjects;

final readonly class PartnerBalanceData
{
    public function __construct(
        public int $partnerId,
        public float $availableBalance = 0.00,
        public float $investedBalance = 0.00,
        public float $totalBalance = 0.00,
    ) {}

    /**
     * Create from array
     *
     * @param  array<string, mixed>  $data
     */
    public static function fromArray(array $data): self
    {
        return new self(
            partnerId: (int) $data['partner_id'],
            availableBalance: (float) ($data['available_balance'] ?? 0.00),
            investedBalance: (float) ($data['invested_balance'] ?? 0.00),
            totalBalance: (float) ($data['total_balance'] ?? 0.00),
        );
    }

    /**
     * Convert to array for model creation
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'partner_id' => $this->partnerId,
            'available_balance' => $this->availableBalance,
            'invested_balance' => $this->investedBalance,
            'total_balance' => $this->totalBalance,
        ];
    }
}
