<?php

namespace App\Http\Requests\CRM;

use Illuminate\Foundation\Http\FormRequest;

class StoreAddressRequest extends FormRequest
{

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        // Enforce residence.* only if type=Residence
        // Enforce mailing.* only if type=Mailing
        // That way, you won't get errors about the other type.
        return [
            'type' => ['required'], // or in:Residence,Mailing

            'residence.line_1'  => ['required_if:type,Residence', 'string', 'max:255'],
            'residence.city_id' => ['required_if:type,Residence', 'exists:cities,id'],

            'mailing.line_1'  => ['required_if:type,Mailing', 'string', 'max:255'],
            'mailing.city_id' => ['required_if:type,Mailing', 'exists:cities,id'],
        ];
    }

}
