<?php

namespace App\Http\Requests\ProjectManagement;

use Illuminate\Foundation\Http\FormRequest;

class ImportIssuesRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'issues' => 'required|array|min:1',
            'issues.*.title' => 'required|string|max:255',
            'issues.*.description' => 'nullable|string',
            'issues.*.type' => 'nullable|in:bug,feature,improvement',
            'issues.*.status' => 'nullable|in:open,in_progress,resolved,closed',
            // 일정 관련
            'issues.*.start_date' => 'nullable|date',
            'issues.*.due_date' => 'nullable|date|after_or_equal:issues.*.start_date',
            'issues.*.estimated_hours' => 'nullable|integer|min:0',
            'issues.*.is_urgent' => 'nullable|boolean',
            // 팀/담당자/고객사 (하이브리드)
            'issues.*.department_id' => 'nullable|integer|exists:departments,id',
            'issues.*.team' => 'nullable|string|max:100',
            'issues.*.assignee_id' => 'nullable|integer|exists:users,id',
            'issues.*.assignee_name' => 'nullable|string|max:100',
            'issues.*.client' => 'nullable|string|max:100',
        ];
    }

    public function messages(): array
    {
        return [
            'issues.required' => 'issues 배열은 필수입니다.',
            'issues.min' => '최소 1개 이상의 이슈가 필요합니다.',
            'issues.*.title.required' => '각 이슈의 title은 필수입니다.',
        ];
    }
}
