<?php

namespace App\Http\Requests\Api\V1;

use Illuminate\Foundation\Http\FormRequest;

class CreateBucketRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:100', 'regex:/^[a-z0-9-]+$/', 'unique:file_buckets,name'],
            'display_name' => ['required', 'string', 'max:255'],
            'description' => ['sometimes', 'string', 'max:1000'],
            'visibility' => ['sometimes', 'in:public,private,mixed'],
            'max_file_size' => ['sometimes', 'integer', 'min:1', 'max:5368709120'], // Max 5GB
            'allowed_mime_types' => ['sometimes', 'array'],
            'allowed_mime_types.*' => ['string'],
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'name.required' => 'A bucket name is required.',
            'name.regex' => 'The bucket name must contain only lowercase letters, numbers, and hyphens.',
            'name.unique' => 'A bucket with this name already exists.',
            'display_name.required' => 'A display name is required.',
            'visibility.in' => 'Visibility must be one of: public, private, mixed.',
        ];
    }
}
