#import "lib.typ": *

#import "jury.typ": jury-content
#import "abstract.typ": keywords-en, keywords-fr, abstract-en, abstract-fr
#import "0_preamble/notations.typ": *

#let draft = if "draft" in sys.inputs {
  assert(
    sys.inputs.draft == "true" or sys.inputs.draft == "false",
    message: "If --input draft=<val> is set, <val> must be 'true', or 'false'"
  )
  sys.inputs.draft == "true"
} else {
  true
}
#let paper_draft = if "paper" in sys.inputs {
  assert(
    sys.inputs.paper == "true" or sys.inputs.paper == "false",
    message: "If --input paper=<val> is set, <val> must be 'true', or 'false'"
  )
  assert(
    draft,
    message: "paper can only be set if --input draft=true is set"
  )
  sys.inputs.draft == "true"
} else {
  false
}
#let preliminary = if "preliminary" in sys.inputs {
  assert(
    sys.inputs.preliminary == "true" or sys.inputs.preliminary == "false",
    message: "If --input preliminary=<val> is set, <val> must be 'true' or 'false'",
  )
  sys.inputs.preliminary == "true"
} else {
  false
}

#let (show_cover, show_body, show_abstracts) = {
  let show_cover = true
  let show_body = true
  let show_abstracts = true
  let abstract-only = false

  if "abstract-only" in sys.inputs {
    assert(
      sys.inputs.abstract-only == "true" or sys.inputs.abstract-only == "false",
      message: "If --input abstract-only=<val> is set, <val> must be 'true', or 'false'"
    )
    if sys.inputs.abstract-only  == "true" {
      show_cover = false
      show_body = false
      show_abstracts = true
      abstract-only = true
    }
  }

  (show_cover, show_body, show_abstracts)
}



#show: matisse-thesis.with(
  title-fr: [Les difficultés de la rétro-ingénierie Android: de l'analyse large échelle au dé-brouillage dynamique],
  // Because "Android Skuldgerries and Other Headache Inducing Fuckeries" won't pass the vibe check
  title-en: [The Woes of Android Reverse Engineering: from Large Scale Analysis to Dynamic Deobfuscation],
  author: "Jean-Marie MINEAU",
  affiliation: "IRISA",
  defense-place: "Rennes",
  defense-date: datetime(
    year: 2025,
    month: 12,
    day: 9,
  ).display("[year]-[month]-[day]"),
  jury-content: jury-content,
  university: "CS",
  keywords-en: keywords-en,
  keywords-fr: keywords-fr,
  abstract-en: abstract-en,
  abstract-fr: abstract-fr,
  //abstract-font-size: 10pt,
  draft: draft,
  show_cover: show_cover,
  show_body: show_body,
  show_abstracts: show_abstracts,
  preliminary: preliminary,
)

// Preamble
#{
  set heading(numbering: none, outlined: false)
  set figure(outlined: false)
  set page(numbering: "i")
  counter(page).update(0)

  include("0_preamble/acknowledgements.typ")

  outline(title: "Table of Contents", indent: auto)
  show outline.entry: it => {
    v(5mm, weak: true)
    it
  }

  outline(title: "Index of Figures", target: figure.where(supplement: [Figure]))
  outline(title: "Index of Tables", target: figure.where(supplement: [Table]))
  outline(title: "Index of Listings", target: figure.where(supplement: [Listing]))
 
  [= List of Acronyms and Notations]

  notation_table

}

// Reset page and figure counters
#counter(page).update(1)
#counter(figure.where(kind: table)).update(0)
#counter(figure.where(kind: image)).update(0)
#counter(figure.where(kind: raw)).update(0)


// Augment interline when compiling to paper draft
#show par: set par(leading: 1.5em) if paper_draft
#show par: set par(spacing: 1.5em) if paper_draft
// Keep interline in table
#show table: set par(leading: 0.65em) if paper_draft

#include("1_introduction/main.typ")
#include("2_background/main.typ")
#include("3_rasta/main.typ")
#include("4_class_loader/main.typ")
#include("5_theseus/main.typ")
#include("6_conclusion/main.typ")

#bibliography("bibliography.bib")

#{
  set heading(numbering: none, outlined: false)
  set figure(outlined: false)
  set page(numbering: "i")
  counter(page).update(0)

  // https://ed-matisse.doctorat-bretagne.fr/fr/soutenance-de-these#p-151
  // > Le manuscrit est normalement rédigé en français (Loi relative à l'emploi de la langue française, 1994). 
  // > Toutefois, il est accepté de bâtir le manuscrit sur la base d'un résumé substantiel en français 
  // > (au moins 4 pages), le reste du manuscrit étant considéré comme des annexes et étant alors rédigé en 
  // > langue étrangère.
  // >
  // > Dans le cas d'une thèse qui ne serait pas rédigée en français, il est conseillé de bien distinguer le 
  // > résumé substantiel des chapitres de la thèse pour éviter d'essuyer un refus de la part de 
  // > l'administration de l'établissement d'inscription (par exemple en l'intitulant résumé en français et 
  // > en ne lui affectant aucun numéro de chapitre).
  //
  include("0_preamble/french_summary.typ")
}
