<?php

namespace App\Data;

use App\Helpers\UrlHelper;
use Spatie\LaravelData\Data;

class PropertyImageData extends Data
{
    public function __construct(
        public string $image_url,
        public bool $is_primary = false,
    ) {}

    public static function fromPropertyImage(\App\Models\PropertyImage $image): self
    {
        return new self(
            image_url: UrlHelper::toFullUrl($image->image_url),
            is_primary: $image->is_primary,
        );
    }

    public function toArray(): array
    {
        return [
            'image_url' => UrlHelper::toFullUrl($this->image_url),
            'is_primary' => $this->is_primary,
        ];
    }
}