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

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

class MusicData extends DataTransferObject
{
    public $title;
    public $body;
    public $user;
    public $musics;
    public $musics_paid;
    public $preview;
    public $is_loaded_music;
    public $is_loaded_paid_music;
    public $is_loaded_preview;
    public $price;
    public $times;
    public $times_paid;
    public $is_paid;
    public $tags;
    public $removedItems;

    public static function fromRequest(MusicFormRequest $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'),

            'musics' => $request->file('musics'),
            'is_loaded_music' => $request->hasFile('musics'),

            'musics_paid' => $request->file('musics_paid'),
            'is_loaded_paid_music' => $request->hasFile('musics_paid'),

            'times' => $request->input('times'),
            'times_paid' => $request->input('times_paid'),

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