<?php

declare(strict_types=1);

namespace App\DataTransferObjects;

final readonly class PartnerBalanceTransactionData
{
    public function __construct(
        public int $partnerId,
        public string $transactionType,
        public float $amount,
        public float $balanceBefore,
        public float $balanceAfter,
        public ?string $description = null,
        public ?string $referenceId = null,
        public ?string $paymentProof = null,
        public ?string $paymentMethodType = null,
        public ?string $paymentDetails = null,
        public string $status = 'pending',
    ) {}

    /**
     * Create from array
     *
     * @param  array<string, mixed>  $data
     */
    public static function fromArray(array $data): self
    {
        return new self(
            partnerId: (int) $data['partner_id'],
            transactionType: $data['transaction_type'],
            amount: (float) $data['amount'],
            balanceBefore: (float) $data['balance_before'],
            balanceAfter: (float) $data['balance_after'],
            description: $data['description'] ?? null,
            referenceId: $data['reference_id'] ?? null,
            paymentProof: $data['payment_proof'] ?? null,
            paymentMethodType: $data['payment_method_type'] ?? null,
            paymentDetails: $data['payment_details'] ?? null,
            status: $data['status'] ?? 'pending',
        );
    }

    /**
     * Convert to array for model creation
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'partner_id' => $this->partnerId,
            'transaction_type' => $this->transactionType,
            'amount' => $this->amount,
            'balance_before' => $this->balanceBefore,
            'balance_after' => $this->balanceAfter,
            'description' => $this->description,
            'reference_id' => $this->referenceId,
            'payment_proof' => $this->paymentProof,
            'payment_method_type' => $this->paymentMethodType,
            'payment_details' => $this->paymentDetails,
            'status' => $this->status,
        ];
    }
}
