<?php
namespace App\Domain\Videos\DataTransferObjects;

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

class VideoData extends DataTransferObject
{
    public $title;
    public $body;
    public $user;
    public $videos;
    public $videos_paid;
    public $preview;
    public $is_loaded_video;
    public $is_loaded_preview;
    public $is_loaded_videos_paid;
    public $price;
    public $is_paid;
    public $tags;
    public $removedItems;

    public static function fromRequest(VideoFormRequest $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') ?? [],

            'preview' => $request->file('preview'),
            'is_loaded_preview' => $request->hasFile('preview'),

            'videos' => $request->file('videos'),
            'is_loaded_video' => $request->hasFile('videos'),

            'videos_paid' => $request->file('videos_paid'),
            'is_loaded_videos_paid' => $request->hasFile('videos_paid'),

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

        ]);
    }
}
