<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MediaRequest extends FormRequest
{
    public function rules(): array
    {
        $rules = [
            'source'    => 'sometimes|string',
            'source_id' => 'sometimes|integer',
            'name'      => 'sometimes|nullable|string',
            'path'      => 'sometimes|string',
            'url'       => 'sometimes|nullable|string',
            'user_id'   => 'sometimes|nullable|exists:users,id',
        ];

        if ($this->isMethod('post')) {
            $rules['source']    = 'required|string';
            $rules['source_id'] = 'required|integer';
            $rules['path']      = 'required|string';
        }

        return $rules;
    }
}
