<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreatePropertyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true; // Authorization handled by middleware
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'property_type' => 'required|integer|in:1,2,3,4,5',
            'title' => 'required|string|min:3|max:255',
            'description' => 'nullable|string|max:2000',
            'monthly_rent' => 'required|numeric|min:0|max:999999.99',
            'deposit_amount' => 'required|numeric|min:0|max:999999.99',
            'address' => 'required|string|min:5|max:500',
            'latitude' => 'nullable|numeric|between:-90,90',
            'longitude' => 'nullable|numeric|between:-180,180',
            'bedrooms' => 'nullable|integer|min:0|max:50',
            'bathrooms' => 'nullable|integer|min:0|max:20',
            'size_sqm' => 'nullable|integer|min:1|max:10000',
            'is_furnished' => 'boolean',
            'status' => 'integer|in:1,2,3,4',
            'is_verified' => 'boolean',
            'images' => 'nullable|array',
            'images.*.image_url' => 'required_with:images|string|max:500',
            'images.*.is_primary' => 'boolean',
            'hostel' => 'nullable|array',
            'hostel.university_nearby' => 'required_with:hostel|string|min:2|max:255',
            'hostel.distance_to_university' => 'required_with:hostel|numeric|min:0|max:1000',
            'hostel.room_sharing' => 'required_with:hostel|integer|in:1,2,3',
            'hostel.gender_restriction' => 'required_with:hostel|integer|in:1,2,3',
            'hostel.meal_plan_available' => 'boolean',
            'hostel.study_room_available' => 'boolean',
            'hostel.curfew_time' => 'nullable|date_format:H:i',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'property_type.in' => 'Property type must be: 1=house, 2=apartment, 3=room, 4=hostel, 5=office',
            'status.in' => 'Status must be: 1=available, 2=occupied, 3=pending, 4=maintenance',
            'hostel.room_sharing.in' => 'Room sharing must be: 1=single, 2=double, 3=triple',
            'hostel.gender_restriction.in' => 'Gender restriction must be: 1=male, 2=female, 3=mixed',
        ];
    }
}