import Mock from 'mockjs'

interface Contacts {
  [key: string]: Array<Person>
}

interface Person {
  id: string,
  name: string,
  isLeader: boolean,
  isDirector: boolean
}

const contacts: Contacts = {
  A: [],
  B: [],
  C: [],
  D: [],
  E: [],
  F: [],
  G: [],
  H: [],
  I: [],
  J: [],
  K: [],
  L: [],
  M: [],
  N: [],
  O: [],
  P: [],
  Q: [],
  R: [],
  S: [],
  T: [],
  U: [],
  V: [],
  W: [],
  X: [],
  Y: [],
  Z: []
}

let hasLeader = false
let hasDirector = false

for (const key in contacts) {
  const length = Mock.mock({
    'number|1-5': 1
  })
  for (let i = 0; i <= length.number; i++) {
    const person: Person = {
      id: key + i,
      name: key + Mock.mock('@cname'),
      isLeader: hasLeader ? false : Mock.mock({ 'boolean|1-2': true }).boolean,
      isDirector: hasDirector ? false : Mock.mock({ 'boolean|1-2': true }).boolean
    }
    hasLeader = hasLeader || person.isLeader
    hasDirector = hasDirector || person.isDirector
    contacts[key].push(person)
  }
}

let flatContacts: Array<Person> = []

for (const key in contacts) {
  flatContacts = flatContacts.concat(contacts[key])
}

export {
  contacts,
  flatContacts,
  Person
}
