///|
/// 冲突检测引擎:这是参赛管家相对 Auto-Lexmount 的核心创新之一。
/// Auto-Lexmount 只做单比赛的流水线,不检查作品跨比赛的规则冲突;
/// 这里一次扫全部 19 个比赛,规则撞了就报警。

///|
pub struct Conflict {
  level : String // "P0":提交会被取消资格;"P1":须调整后才能交
  competition : String
  work : String
  message : String
}

///|
pub fn join_strings(items : Array[String], sep : String) -> String {
  let mut out = ""
  for i in 0.. 0 {
      out = out + sep
    }
    out = out + items[i]
  }
  out
}

///|
pub fn contains_string(items : Array[String], target : String) -> Bool {
  for i in 0.. Array[Conflict] {
  let result : Array[Conflict] = []
  for i in 0.. 0) {
      let reasons : Array[String] = []
      if work.first_public_date != "" {
        reasons.push(
          "活动开始前已公开(" + work.first_public_date + ")",
        )
      }
      if work.submitted_to.length() > 0 {
        reasons.push("已投 " + join_strings(work.submitted_to, "、"))
      }
      result.push({
        level: "P0",
        competition: comp.name,
        work: work.name,
        message: "首次发布冲突:" +
        join_strings(reasons, ",") +
        ",违反“活动期间首次公开发布、不得使用已参加其他比赛的作品”",
      })
    }
    if comp.requires_new_work && work.first_public_date != "" {
      result.push({
        level: "P1",
        competition: comp.name,
        work: work.name,
        message: "须新做:作品已有公开版本(" +
        work.first_public_date +
        "),不能直接交",
      })
    }
    if comp.requires_no_prior_entry && work.submitted_to.length() > 0 {
      result.push({
        level: "P0",
        competition: comp.name,
        work: work.name,
        message: "原创条款冲突:已投 " +
        join_strings(work.submitted_to, "、") +
        ",违反“参赛作品必须为原创且未参加过其他国家级公开比赛”",
      })
    }
  }
  result
}

///|
/// 同一天有 2 个及以上截止的日期(按 deadline_date 分组)。
pub fn collision_dates(competitions : Array[Competition]) -> Array[String] {
  let result : Array[String] = []
  let seen : Array[String] = []
  for i in 0.. 1 {
      result.push(date)
    }
  }
  result
}

///|
/// 截止撞期提醒:同一天多个截止,列出当天所有比赛。
pub fn collision_conflicts(
  competitions : Array[Competition],
) -> Array[Conflict] {
  let result : Array[Conflict] = []
  let dates = collision_dates(competitions)
  for d in 0.. Array[Conflict] {
  let result : Array[Conflict] = []
  for i in 0.. Bool {
  let list = conflicts_for_competition(conflicts, name)
  for i in 0..