<?php

namespace App\Http\Requests\ProjectManagement;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            // 프로젝트
            'project' => 'required|array',
            'project.name' => 'required|string|max:255',
            'project.description' => 'nullable|string',
            'project.status' => 'nullable|in:active,completed,on_hold',
            'project.start_date' => 'nullable|date',
            'project.end_date' => 'nullable|date|after_or_equal:project.start_date',

            // 작업 목록
            'tasks' => 'nullable|array',
            'tasks.*.title' => 'required|string|max:255',
            'tasks.*.description' => 'nullable|string',
            'tasks.*.status' => 'nullable|in:todo,in_progress,done',
            'tasks.*.priority' => 'nullable|in:low,medium,high',
            'tasks.*.due_date' => 'nullable|date',
            'tasks.*.is_urgent' => 'nullable|boolean',
            'tasks.*.assignee_id' => 'nullable|integer|exists:users,id',
            'tasks.*.assignee_name' => 'nullable|string|max:100',

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

    public function messages(): array
    {
        return [
            'project.required' => 'project 객체는 필수입니다.',
            'project.name.required' => 'project.name은 필수입니다.',
            'tasks.*.title.required' => '각 작업의 title은 필수입니다.',
            'tasks.*.issues.*.title.required' => '각 이슈의 title은 필수입니다.',
        ];
    }
}
