<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class ImportBlogRequest extends FormRequest
{
    /**
     * @return bool
     */
    public function authorize()
    {
        return Auth::check();
    }

    /**
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'file' => [
                'required',
                'file',
                'mimes:xml,csv,txt',
            ],
            'format' => [
                'required',
                'string',
                'in:wordpress,csv',
            ],
            'column_mapping' => [
                'required_if:format,csv',
                'array',
            ],
            'column_mapping.title' => [
                'required_if:format,csv',
                'string',
            ],
            'content_element_mapping' => [
                'sometimes',
                'array',
            ],
            'content_element_mapping.*' => [
                'array',
            ],
            'content_element_mapping.*.*' => [
                'string',
            ],
            'template_id' => [
                'required',
                'integer',
                'exists:page_templates,id',
            ],
        ];
    }
}
