<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'category_id' => 'required|exists:categories,id',
            'type' => 'required|in:offer,request',
            'title' => 'required|string|max:255',
            'description' => 'required|string',
            'price_type' => 'required|in:fixed,negotiable,free_to_offer',
            'price_min' => 'nullable|integer|min:0',
            'price_max' => 'nullable|integer|min:0|gte:price_min',
            'price_label' => 'nullable|string|max:100',
            'location' => 'nullable|string|max:100',
            'is_remote' => 'boolean',
            'deadline' => 'nullable|date|after:now',
            'tags' => 'nullable|array|max:10',
            'tags.*' => 'string|max:50',
            'image' => 'nullable|image|mimes:jpg,jpeg,png,webp|max:100',
        ];
    }

    public function messages(): array
    {
        return [
            'category_id.required' => 'Kategori wajib dipilih',
            'category_id.exists' => 'Kategori tidak valid',
            'type.required' => 'Tipe post wajib dipilih',
            'type.in' => 'Tipe post harus offer atau request',
            'title.required' => 'Judul wajib diisi',
            'description.required' => 'Deskripsi wajib diisi',
            'price_type.required' => 'Tipe harga wajib dipilih',
            'price_max.gte' => 'Harga maksimal harus lebih besar dari harga minimal',
            'deadline.after' => 'Deadline harus setelah sekarang',
        ];
    }
}
