<?php

namespace App\Http\Requests\WorkResult;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'work_order_id' => 'required|integer|exists:work_orders,id',
            'work_order_item_id' => 'nullable|integer|exists:work_order_items,id',
            'lot_no' => 'required|string|max:50',
            'work_date' => 'required|date',
            'process_type' => 'nullable|in:screen,slat,bending',
            'product_name' => 'required|string|max:200',
            'specification' => 'nullable|string|max:100',
            'production_qty' => 'required|integer|min:0',
            'good_qty' => 'nullable|integer|min:0',
            'defect_qty' => 'required|integer|min:0',
            'is_inspected' => 'nullable|boolean',
            'is_packaged' => 'nullable|boolean',
            'worker_id' => 'nullable|integer|exists:users,id',
            'memo' => 'nullable|string|max:2000',
        ];
    }

    public function messages(): array
    {
        return [
            'work_order_id.required' => __('validation.required', ['attribute' => '작업지시']),
            'work_order_id.exists' => __('validation.exists', ['attribute' => '작업지시']),
            'lot_no.required' => __('validation.required', ['attribute' => '로트번호']),
            'work_date.required' => __('validation.required', ['attribute' => '작업일']),
            'product_name.required' => __('validation.required', ['attribute' => '품목명']),
            'production_qty.required' => __('validation.required', ['attribute' => '생산수량']),
            'defect_qty.required' => __('validation.required', ['attribute' => '불량수량']),
        ];
    }
}
