// Defensive resource limits for untrusted robots.txt input.

///|
pub struct Limits {
  max_input_bytes : Int
  max_lines : Int
  max_groups : Int
  max_user_agents_per_group : Int
  max_rules_per_group : Int
  max_pattern_bytes : Int
  max_record_bytes : Int
} derive(Eq, Debug)

///|
pub fn Limits::default() -> Limits {
  {
    max_input_bytes: 512 * 1024,
    max_lines: 10000,
    max_groups: 1000,
    max_user_agents_per_group: 64,
    max_rules_per_group: 10000,
    max_pattern_bytes: 8192,
    max_record_bytes: 8192,
  }
}

///|
pub fn Limits::strict() -> Limits {
  {
    max_input_bytes: 64 * 1024,
    max_lines: 2000,
    max_groups: 256,
    max_user_agents_per_group: 16,
    max_rules_per_group: 2048,
    max_pattern_bytes: 1024,
    max_record_bytes: 2048,
  }
}

///|
pub fn Limits::permissive() -> Limits {
  {
    max_input_bytes: 8 * 1024 * 1024,
    max_lines: 200000,
    max_groups: 20000,
    max_user_agents_per_group: 512,
    max_rules_per_group: 200000,
    max_pattern_bytes: 65536,
    max_record_bytes: 65536,
  }
}

///|
pub fn Limits::custom(
  max_input_bytes : Int,
  max_lines : Int,
  max_groups : Int,
  max_user_agents_per_group : Int,
  max_rules_per_group : Int,
  max_pattern_bytes : Int,
  max_record_bytes : Int,
) -> Limits {
  {
    max_input_bytes,
    max_lines,
    max_groups,
    max_user_agents_per_group,
    max_rules_per_group,
    max_pattern_bytes,
    max_record_bytes,
  }
}

///|
pub fn Limits::max_input_bytes(self : Limits) -> Int {
  self.max_input_bytes
}

///|
pub fn Limits::max_lines(self : Limits) -> Int {
  self.max_lines
}

///|
pub fn Limits::max_groups(self : Limits) -> Int {
  self.max_groups
}

///|
pub fn Limits::max_user_agents_per_group(self : Limits) -> Int {
  self.max_user_agents_per_group
}

///|
pub fn Limits::max_rules_per_group(self : Limits) -> Int {
  self.max_rules_per_group
}

///|
pub fn Limits::max_pattern_bytes(self : Limits) -> Int {
  self.max_pattern_bytes
}

///|
pub fn Limits::max_record_bytes(self : Limits) -> Int {
  self.max_record_bytes
}