# Recipe DAG: peanut butter cookies
# Source: John Kanell, Preppy Kitchen, "Peanut Butter Cookies Recipe" (instructions paraphrased)
#
# Changes from the original:
#   - UK terms and units. The gram weights are as published; cups are gone.
#     all-purpose flour > plain flour, brown sugar > light brown soft sugar, sugar > caster sugar,
#     baking sheet > baking tray, parchment paper > baking parchment, 350F > 180°C / 160°C fan / gas 4.
#   - 1 US large egg > 1 UK medium, which is the same size (about 55g).
#   - "One inch balls" doesn't fit 18 cookies from about 800g of dough, so the balls are given by
#     weight (about 45g) instead.
#   - The original bakes on "baking sheets" without saying how many. Here it's trays of 9, baked one
#     at a time, so you shape the next tray while one bakes. Each batch cools completely on its own
#     tray, as the original says, so you need one tray per 9 cookies.
#   - The count chips (9 to 36) scale the ingredients and the number of trays. At 9 or 27 you need
#     half an egg; the step says how to measure it.
#   - The original uses salted peanut butter, with 1/4 to 1/2 tsp sea salt if yours isn't. Here the
#     peanut butter is unsalted, so the salt is always in: 1/2 tsp fine sea salt, the top of the range.
#   - Hands-on times are our estimates. Cooling "completely" is taken as 30 minutes after the last
#     tray comes out.

recipe:
  id: peanut_butter_cookies
  code: peanut-butter-cookies   # short URL: /peanut-butter-cookies
  category: Sweet
  title: Peanut butter cookies
  yield: { servings: 18, unit: cookie, options: [9, 18, 27, 36] }

derived:
  trays: "=n / 9"

resources:
  cook:     { kind: cook,   capacity: 1 }
  oven:     { kind: oven,   capacity: 1, state: { key: temperature, setup: 12m } }
  bowl:     { kind: vessel, capacity: 1, name: medium bowl }
  sieve:    { kind: tool,   capacity: 1 }
  whisk:    { kind: tool,   capacity: 1 }
  mixer:    { kind: tool,   capacity: 1, name: stand mixer with the paddle }
  fork:     { kind: tool,   capacity: 1 }
  trays:    { kind: vessel, capacity: 1, name: "baking trays, one per 9 cookies" }

products:
  flour:         { kind: ingredient, qty: { amount: 180, unit: g, scale: linear }, name: plain flour }
  baking_powder: { kind: ingredient, qty: { amount: 0.75, unit: tsp, scale: linear } }
  butter:        { kind: ingredient, qty: { amount: 113, unit: g, scale: linear }, name: unsalted butter, note: at room temperature }
  brown_sugar:   { kind: ingredient, qty: { amount: 100, unit: g, scale: linear }, name: light brown soft sugar }
  caster_sugar:  { kind: ingredient, qty: { amount: 100, unit: g, scale: linear } }
  salt:          { kind: ingredient, qty: { amount: 0.5, unit: tsp, scale: linear }, name: fine sea salt }
  peanut_butter: { kind: ingredient, qty: { amount: 250, unit: g, scale: linear }, name: smooth unsalted peanut butter, note: "if it's the natural kind, stir the oil back in first" }
  egg:           { kind: ingredient, qty: { amount: 1, unit: medium, scale: linear }, note: at room temperature }
  vanilla:       { kind: ingredient, qty: { amount: 1, unit: tsp, scale: linear }, name: vanilla extract }

  oven_0:        { kind: intermediate, name: hot oven, state: 180°C / 160°C fan / gas 4 }
  trays_lined:   { kind: intermediate, name: lined baking tray(s), hold: { max: 24h } }
  dry_mix:       { kind: intermediate, name: flour and baking powder, vessel: bowl, hold: { max: 4h } }
  creamed:       { kind: intermediate, name: creamed butter and sugar, hold: { max: 30m } }
  pb_mix:        { kind: intermediate, name: peanut butter mix, hold: { max: 30m } }
  dough_0:       { kind: intermediate, name: cookie dough, hold: { max: 1h } }
  shaped_$i:     { kind: intermediate, repeat: trays, name: tray $i of cookies, hold: { max: 30m } }
  dough_$i:      { kind: intermediate, repeat: trays, name: rest of the dough, hold: { max: 1h } }
  baked_$i:      { kind: intermediate, repeat: trays, name: tray $i from the oven }
  oven_$i:       { kind: intermediate, repeat: trays, name: hot oven, state: 180°C / 160°C fan / gas 4 }
  cooled:        { kind: intermediate, name: cooled cookies on their trays }
  cookies:       { kind: final, state: cooled and firm, hold: { max: 7d, then: going stale } }

steps:
  preheat:
    title: Preheat the oven
    text: Set the oven to 180°C (160°C fan) / gas mark 4.
    outputs: [oven_0]
    phases:
      - { kind: active, duration: 15s }
      - { kind: passive, duration: 12m }
    uses: [{ resource: oven, requires: { temperature: 180 } }]

  line_trays:
    title: Line the trays
    text: Line $trays baking tray(s) with baking parchment.
    outputs: [trays_lined]
    phases: [{ kind: active, duration: 1m }]
    uses: [trays]

  sift_dry:
    title: Sift the flour
    text: Sift the flour and baking powder into a medium bowl, then whisk to combine.
    inputs: [flour, baking_powder]
    outputs: [dry_mix]
    phases: [{ kind: active, duration: 1m }]
    uses: [bowl, sieve, whisk]

  cream:
    title: Cream the butter and sugars
    text: Cream the butter and both sugars in a stand mixer fitted with the paddle, with the salt.
    inputs: [butter, brown_sugar, caster_sugar, salt]
    outputs: [creamed]
    phases: [{ kind: active, duration: 3m }]
    done_when: light and fluffy
    uses: [mixer]

  add_pb:
    title: Add the peanut butter
    text: Add the peanut butter and mix until incorporated.
    inputs: [creamed, peanut_butter]
    outputs: [pb_mix]
    phases: [{ kind: active, duration: 1m }]
    uses: [mixer]

  add_egg:
    title: Add the egg, vanilla and flour
    text: Mix in the egg and vanilla, then add the flour mixture and beat until incorporated. If you need half an egg, beat one and use 25g.
    inputs: [pb_mix, egg, vanilla, dry_mix]
    outputs: [dough_0]
    phases: [{ kind: active, duration: 2m }]
    done_when: no dry flour left
    uses: [mixer]

  shape_$i:
    repeat: trays
    title: Shape tray $i
    text: Roll 9 balls of dough, about 45g each, and space them out on a lined tray. Flatten each with the fork in a criss-cross pattern, as before.
    first:
      title: Shape the first tray
      text: Roll 9 balls of dough, about 45g each, and space them out on a lined tray. Flatten each with a fork in a criss-cross pattern. Pull the fork away rather than lifting it, for a clean release.
      inputs: [dough_0, trays_lined]
    inputs: [dough_$prev]
    outputs: [shaped_$i, dough_$i]
    phases: [{ kind: active, duration: 4m }]
    uses: [fork]

  bake_$i:
    repeat: trays
    title: Bake tray $i
    text: Bake for about 10 minutes, as before, then take the tray out and leave the cookies on it.
    first:
      title: Bake the first tray
      text: Bake for about 10 minutes, until almost done, then take the tray out and leave the cookies on it. They'll keep cooking from their own heat.
    inputs: [shaped_$i, oven_$prev]
    outputs: [baked_$i, oven_$i]
    phases:
      - { kind: active, duration: 15s }
      - { kind: passive, duration: 10m, timer: true }
    done_when: the edges are just starting to colour
    uses: [{ resource: oven, requires: { temperature: 180 } }]

  cool:
    title: Cool the cookies
    text: Leave the cookies to cool completely where they are. They're very soft out of the oven and need to set before you move them.
    inputs: [baked_$trays]
    outputs: [cooled]
    phases: [{ kind: passive, duration: 30m }]
    done_when: firm enough to lift
    uses: [trays]

  store:
    title: Lift off the cookies
    text: Lift the cookies off the parchment. They keep in an airtight tin for up to a week.
    inputs: [cooled]
    outputs: [cookies]
    phases: [{ kind: active, duration: 1m }]
