<?php

namespace App\Data;

use Spatie\LaravelData\Data;

class RentalAgreementData extends Data
{
    public function __construct(
        public int $booking_id,
        public int $property_id,
        public int $tenant_id,
        public int $landlord_id,
        public string $start_date,
        public ?string $end_date = null, // recurring/indefinite stays can leave null
        public float $monthly_rent,
        public float $deposit_amount,
        public ?string $contract_document_url = null,
        public bool $is_active = true,
    ) {}

    public static function fromRentalAgreement(\App\Models\RentalAgreement $agreement): self
    {
        return new self(
            booking_id: $agreement->booking_id,
            property_id: $agreement->property_id,
            tenant_id: $agreement->tenant_id,
            landlord_id: $agreement->landlord_id,
            start_date: $agreement->start_date->format('Y-m-d'),
            end_date: $agreement->end_date?->format('Y-m-d'),
            monthly_rent: $agreement->monthly_rent,
            deposit_amount: $agreement->deposit_amount,
            contract_document_url: $agreement->contract_document_url,
            is_active: $agreement->is_active,
        );
    }

    public function toArray(): array
    {
        return [
            'booking_id' => $this->booking_id,
            'property_id' => $this->property_id,
            'tenant_id' => $this->tenant_id,
            'landlord_id' => $this->landlord_id,
            'start_date' => $this->start_date,
            'end_date' => $this->end_date,
            'monthly_rent' => $this->monthly_rent,
            'deposit_amount' => $this->deposit_amount,
            'contract_document_url' => $this->contract_document_url,
            'is_active' => $this->is_active,
        ];
    }
}
