Call forwarding while keeping the caller id

Sorry if this is a stupid question I am new to this product.

But basically I need to get calls that are coming in on a sip trunk and forward them to a local phone number. I need to change the local number they get forwarded to based on what number they dialed when they came in. I need to then also make the caller id that comes out of the system the same as when it came in.

So basically I want to figure out what number the user dialed to get to the system, I then will need to forward that call to a specific local number (based on the incoming phone number dialed). But when the phone rings on the local number I would like to have the caller id of the caller not of the system that is forwarding calls.

I hope that makes sense,

Thanks for your help in advance.