<?php

namespace App\Http\Requests\ESign;

use App\Models\ESign\EsignContract;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'title' => 'required|string|max:200',
            'description' => 'nullable|string|max:2000',
            'sign_order_type' => 'nullable|string|in:' . implode(',', EsignContract::SIGN_ORDERS),
            'file' => 'required|file|mimes:pdf|max:20480',
            'expires_at' => 'nullable|date|after:now',
            'creator_name' => 'required|string|max:100',
            'creator_email' => 'required|email|max:255',
            'creator_phone' => 'nullable|string|max:20',
            'counterpart_name' => 'required|string|max:100',
            'counterpart_email' => 'required|email|max:255',
            'counterpart_phone' => 'nullable|string|max:20',
        ];
    }

    public function messages(): array
    {
        return [
            'title.required' => __('validation.required', ['attribute' => '계약 제목']),
            'file.required' => __('validation.required', ['attribute' => 'PDF 파일']),
            'file.mimes' => __('validation.mimes', ['attribute' => '파일', 'values' => 'PDF']),
            'file.max' => __('validation.max.file', ['attribute' => '파일', 'max' => '20MB']),
            'creator_name.required' => __('validation.required', ['attribute' => '작성자 이름']),
            'creator_email.required' => __('validation.required', ['attribute' => '작성자 이메일']),
            'counterpart_name.required' => __('validation.required', ['attribute' => '상대방 이름']),
            'counterpart_email.required' => __('validation.required', ['attribute' => '상대방 이메일']),
        ];
    }
}
