<?php

namespace App\Http\Requests\DailyLog;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'log_date' => ['sometimes', 'date', 'date_format:Y-m-d'],
            'project_id' => ['nullable', 'integer', 'exists:admin_pm_projects,id'],
            'summary' => ['nullable', 'string', 'max:5000'],
            'entries' => ['nullable', 'array'],
            'entries.*.id' => ['nullable', 'integer', 'exists:admin_pm_daily_log_entries,id'],
            'entries.*.assignee_type' => ['required_with:entries', 'in:team,user'],
            'entries.*.assignee_id' => ['nullable', 'integer'],
            'entries.*.assignee_name' => ['required_with:entries', 'string', 'max:100'],
            'entries.*.content' => ['required_with:entries', 'string', 'max:2000'],
            'entries.*.status' => ['nullable', 'in:todo,in_progress,done'],
        ];
    }

    public function attributes(): array
    {
        return [
            'log_date' => '로그 날짜',
            'project_id' => '프로젝트',
            'summary' => '요약',
            'entries' => '항목',
            'entries.*.id' => '항목 ID',
            'entries.*.assignee_type' => '담당자 유형',
            'entries.*.assignee_id' => '담당자 ID',
            'entries.*.assignee_name' => '담당자 이름',
            'entries.*.content' => '업무 내용',
            'entries.*.status' => '상태',
        ];
    }

    public function messages(): array
    {
        return [
            'entries.*.assignee_name.required_with' => '담당자 이름은 필수입니다.',
            'entries.*.content.required_with' => '업무 내용은 필수입니다.',
        ];
    }
}
