<?php

namespace App\Domain\Images\DataTransferObjects;

use App\Http\Requests\ImageFormRequest;
use Spatie\DataTransferObject\DataTransferObject;

class ImageData extends DataTransferObject
{
    public $title;
    public $body;
    public $user;
    public $photos;
    public $price;
    public $tags;
    public $is_paid;
    public $is_loaded_photos_paid;
    public $is_loaded_photos;
    public $photos_paid;
    public $removedItems;

    public static function fromRequest(ImageFormRequest $request)
    {
        return new self([
            'title' => $request->input('title'),
            'body' =>  $request->input('body'),
            'price' =>  $request->input('price'),
            'is_paid' =>  $request->input('is_paid'),
            'user' =>  auth()->user(),
            'tags' =>  $request->input('tags') ?? [],

            'photos' => $request->file('photos'),
            'is_loaded_photos' => $request->hasFile('photos'),

            'photos_paid' => $request->file('photos_paid'),
            'is_loaded_photos_paid' => $request->hasFile('photos_paid'),

            'removedItems' =>  $request->input('removedItems') ?? [],
        ]);
    }
}
