...
Validate merge_person_id UUID
In case of error - return 422
Find preperson by id in mpi.prepersons
In case of error - return 422 (Such preperson doesn't exist)
Check preperson status is active in mpi.prepersons
In case of error - return 409 (Preperson is not active)
Check if exists another preperson merge requests with status NEW or APPROVED for this preperson
if exists - update status of another requests to REJECTED
Check if preperson has at least one episode
if no episodes - return 422 (Preperson has no episodes)
Validate employee
Extract user_id and legal_entity_id from token and find corresponding employee_id
Check employee status is APPROVED
In case of error - return 422 error (Only active employee can create merge request)
Validate authorize_with
If submitted, validate authorize_with field for a person as described on create Person request process. But for success case set it to il.merge_requests.authentication_method_current field instead.
...