Q:

How to add a caption next to figure elegantly (with control parameters)?

I need to have a figure function that place the caption next to it.
The figure ratio should be controlled with "xtextwidth" and the caption ratio is "ytextwidth". So far so good!
This function should control the distances of the figure from the red vertical borders with parameter "1" and "2", left and right side respectively.
Similarly, parameters "3" and "4" controls the distances of caption from the green vertical borders. 

I have tried hard could not achieve. If any one helps me to create this template/preamble, I appreciate a lot.
This is what I have so far:
\begin{figure}[!h]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={right,center},capbesidewidth=4cm,floatrowsep=quad}}]{figure}[\FBwidth]
{\caption{xyzxyz xyz xyz xyz xyz.}\label{Fig:1}}
{\centering\includegraphics[width=0.5\textwidth]{chapter-1/Figures/1.png}} 
\end{figure}

It creates something like this! but it is based on trial & error too much.

EDIT/UPDATE:
If I follow the answer provided by @leandriis it creates something like this:
I want to be able to control left margin for the figure and the right for the caption. How can I do that?

SOLUTION:
Werner's solution worked well! Please check my comment at there if you are using \usepackage{multicol}.

A:

Here is a key-valued approach to what you're after. Keys you can set include

left - the left margin/gap (default = 0pt)
right - the right margin/gap (default = 0pt)
figcapsep - the horizontal gap between the figure/image and the caption (default = \tabcolsep)
figwidth - the width of the figure/image (calculated if not specified)
capwidth - the width of the caption (calculated if not specified)
figlabel - the \label that should be used with \caption
captiontoc - the optional argument using in \caption[<ToC>]{<text>}.

The entire construction fits within \linewidth.

\documentclass{article}

\usepackage[margin=1in,showframe]{geometry}% Just for this example
\usepackage[nopar]{lipsum}% Just for this example
\usepackage{xkeyval,float}
\usepackage[export]{adjustbox}

\makeatletter
\define@cmdkey{iac}{left}[0pt]{}% \cmdKV@iac@left
\define@cmdkey{iac}{right}[0pt]{}% \cmdKV@iac@right
\define@cmdkey{iac}{figcapsep}[\tabcolsep]{}% \cmdKV@iac@figcapsep
\define@cmdkey{iac}{figwidth}[\relax]{}% \cmdKV@iac@figwidth
\define@cmdkey{iac}{capwidth}[\relax]{}% \cmdKV@iac@capwidth
\define@cmdkey{iac}{figlabel}[\relax]{}% \cmdKV@iac@figlabel
\define@cmdkey{iac}{captiontoc}[\relax]{}% \cmdKV@iac@captiontoc

\newcommand{\imageandcaption}[3][]{%
  \setkeys{iac}{
    left,right,figcapsep,figwidth,capwidth,figlabel,captiontoc,% Set default keys
    #1% Set updated keys
  }%
  \expandafter\ifx\cmdKV@iac@figwidth\relax% No figure width supplied
    \expandafter\ifx\cmdKV@iac@capwidth\relax% No caption width supplied
      \def\cmdKV@iac@figwidth{.5\dimexpr\linewidth-\cmdKV@iac@left-\cmdKV@iac@right-\cmdKV@iac@figcapsep}%
      \def\cmdKV@iac@capwidth{\cmdKV@iac@figwidth}%
    \else% Caption width provided
      \def\cmdKV@iac@figwidth{\dimexpr\linewidth-\cmdKV@iac@left-\cmdKV@iac@right-\cmdKV@iac@figcapsep-\cmdKV@iac@capwidth}%
    \fi
  \else% Figure width supplied
    \expandafter\ifx\cmdKV@iac@capwidth\relax% No caption width supplied
      \def\cmdKV@iac@capwidth{\dimexpr\linewidth-\cmdKV@iac@left-\cmdKV@iac@right-\cmdKV@iac@figcapsep-\cmdKV@iac@figwidth}%
    \fi
  \fi
  \hspace*{\cmdKV@iac@left}% Indent from left margin
  \includegraphics[valign=c,width=\cmdKV@iac@figwidth]{#2}% Insert image
  \hspace*{\cmdKV@iac@figcapsep}% Space between image and caption
  \begin{minipage}{\cmdKV@iac@capwidth}
    \expandafter\ifx\cmdKV@iac@captiontoc\relax
      \caption{#3}% \caption without ToC entry
    \else
      \caption[\cmdKV@iac@captiontoc]{#3}% \caption with ToC entry
    \fi
    \expandafter\ifx\cmdKV@iac@figlabel\relax\else
      \label{\cmdKV@iac@figlabel}%
    \fi
  \end{minipage}%
  \hspace*{\cmdKV@iac@right}% Space on right of construction
}
\makeatother

\begin{document}

See Figure~\ref{fig:figure1}.\sloppy

\begin{figure}[H]
  \imageandcaption[
    left=10pt,
    figwidth=.3\linewidth,
    capwidth=.6\linewidth,
    figlabel=fig:figure1%
  ]
  {example-image-a}{This is a caption}
\end{figure}

\lipsum[2]

\begin{figure}[H]
  \raggedleft
  \imageandcaption[
    right=10pt,
    figwidth=.6\linewidth,
    capwidth=.3\linewidth,
    figlabel=fig:figure2]
  {example-image-b}{\lipsum[2]}
\end{figure}

\lipsum[2]

\begin{figure}[H]
  \imageandcaption
    {example-image-c}{\lipsum[2]}
\end{figure}

\end{document}

