id: shaken-structures

argument-types:
  structure: lookup('structure')
  pga: nullable(lookup('hazard'))
  ground: nullable(lookup('ground-type'))

return-type:
  ground_conditions: nullable(text)
  shake_factor: nullable(integer)
  shake: nullable(integer)
  repair_cost: nullable(integer)

filter: is_not_null(pga) and is_not_null(ground)

  filter: structure.type = 'house'
    filter: ground.type = 'sand'
      function:
        ground_conditions: 'sandy'
        shake: pga.value
        shake_factor: 1
    filter: ground.type = 'rock'
      function:
        ground_conditions: 'rocky'
        shake: pga.value
        shake_factor: 5

  default:
    function:
      ground_conditions: ground.type
      shake: pga.value
      shake_factor: 10

default:
  function:
    ground_conditions: 'unknown'
    shake: 0
    shake_factor: 0

post:
  ground_conditions: ground_conditions
  shake: shake
  shake_factor: shake_factor
  repair_cost: structure.value * shake * shake_factor
