Domgen.repository(:AppConfig) do |repository|
  repository.enable_facet(ENV['DB_TYPE'] == 'pg' ? :pgsql : :mssql)
  repository.enable_facets(:jpa, :ejb)
  repository.disable_facets(:redfish)

  repository.java.base_package = 'iris.appconfig'
  repository.application.service_library = true

  repository.data_module(:AppConfig) do |data_module|

    data_module.struct(:SystemSettingDTO) do |t|
      t.text(:Code)
      t.text(:Value)
    end

    data_module.entity(:SystemSetting) do |t|
      t.integer(:ID, :primary_key => true)
      t.string(:Code, 255, :immutable => true, :unique => true)
      t.text(:Value)

      t.query(:FindByCode)
      t.query(:GetByCode)
    end

    data_module.service(:SystemSettingService) do |s|
      s.method(:GetSetting) do |m|
        m.text(:Code)
        m.returns(:text, :nullable => true)
      end
      s.method(:SetSetting) do |m|
        m.text(:Code)
        m.text(:Value)
      end
    end

    data_module.service(:FeatureFlagService) do |s|
      s.method(:IsFeatureEnabled) do |m|
        m.text(:Feature)
        m.returns(:boolean)
      end
      s.method(:EnableFeature) do |m|
        m.text(:Feature)
      end
      s.method(:DisableFeature) do |m|
        m.text(:Feature)
      end
    end
  end
end
