<?php

namespace App\Modules\HR\Organization\Requests;

trait PreparesOrganizationFormData
{
    protected function prepareForValidation(): void
    {
        $payload = [];

        if ($this->has('is_active')) {
            $payload['is_active'] = filter_var($this->input('is_active'), FILTER_VALIDATE_BOOLEAN);
        }

        foreach (['min_salary', 'max_salary', 'description', 'address', 'department_id', 'section_id', 'branch_id'] as $field) {
            if ($this->exists($field) && $this->input($field) === '') {
                $payload[$field] = null;
            }
        }

        if ($payload !== []) {
            $this->merge($payload);
        }
    }
}
