Modelling Energy Market

Good day. I am very new to GAMS, but have been able to develop simple energy system operation and planning models. I am now trying to replicate an energy market model where

  1. The energy system optimises
  2. Then decide to offer/bid in a local market if it has surplus/deficit
  3. Then if energy needs are unfulfilled the energy system offers/bids to the district market

I am not sure how to formulate this in Gams.
I am not sure of the way in which I should organise all the equations in GAMS to get the process I want.
Can someone help?