class AuthorisationServiceInternal implements AuthorisationService {

    @Transactional
    @Override
    public CmsResponse<CreateAuthorisationResponse> createAuthorisation(AuthorisationParentHolder parentHolder, CreateAuthorisationRequest request) {
        String parentId = parentHolder.getParentId();
        AuthorisationType authorisationType = parentHolder.getAuthorisationType();
        AuthService authService = authServiceResolver.getAuthService(authorisationType);
        Optional<Authorisable> parentOptional = authService.getNotFinalisedAuthorisationParent(parentId);

        if (parentOptional.isEmpty()) {
            log.info("Authorisation type: [{}], Parent ID: [{}]. Create authorisation has failed, because authorisation's parent couldn't be found",
                     authorisationType, parentId);
            return CmsResponse.<CreateAuthorisationResponse>builder()
                       .error(LOGICAL_ERROR)
                       .build();
        }

        authorisationClosingService.closePreviousAuthorisationsByParent(parentId, authorisationType, request.getPsuData());

        Authorisable authorisationParent = parentOptional.get();
        AuthorisationEntity newAuthorisation = authService.saveAuthorisation(request, authorisationParent);

        CreateAuthorisationResponse response = new CreateAuthorisationResponse(newAuthorisation.getExternalId(), newAuthorisation.getScaStatus(), authorisationParent.getInternalRequestId(authorisationType), request.getPsuData());
        return CmsResponse.<CreateAuthorisationResponse>builder()
                   .payload(response)
                   .build();

    }

}