<?php

declare(strict_types=1);

namespace App\Modules\Payments\Domain;

class Payment
{
    public function __construct(
        private readonly string $id,
        private readonly string $tenantId,
        private readonly string $memberId,
        private readonly float $amount,
        private readonly string $method,
        private readonly string $bookedAt,
        private readonly string $reconciliationState = 'neu'
    ) {
    }

    public function id(): string
    {
        return $this->id;
    }

    public function tenantId(): string
    {
        return $this->tenantId;
    }

    public function memberId(): string
    {
        return $this->memberId;
    }

    public function amount(): float
    {
        return $this->amount;
    }

    public function method(): string
    {
        return $this->method;
    }

    public function bookedAt(): string
    {
        return $this->bookedAt;
    }

    public function reconciliationState(): string
    {
        return $this->reconciliationState;
    }

    public function isCancellable(): bool
    {
        return $this->reconciliationState !== 'storniert';
    }

    public function canBeCancelledByResponsible(): bool
    {
        return $this->isCancellable();
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id(),
            'tenant_id' => $this->tenantId(),
            'member_id' => $this->memberId(),
            'amount' => $this->amount(),
            'method' => $this->method(),
            'booked_at' => $this->bookedAt(),
            'reconciliation_state' => $this->reconciliationState(),
            'cancellable' => $this->canBeCancelledByResponsible(),
        ];
    }
}
