{"version":3,"sources":["../../src/models/business-board.model.ts"],"sourcesContent":["import { BusinessAgent } from \"./business-agent.model\";\n\n/**\n * Business Board is a collection of business agents that take the final decisions about a business\n */\nexport class BusinessBoard {\n  members: { agent: BusinessAgent; participation: number | unknown }[] = [];\n\n  /**\n   * Add a new member to the board\n   *\n   * @param {BusinessAgent} newMember member to be added\n   * @param {number} participation percentage of weight in the decisions, if known\n   */\n  addMember(newMember: BusinessAgent, participation?: number): void {\n    this.members.push({ agent: newMember, participation });\n  }\n\n  getController(): BusinessAgent {\n    let controller: BusinessAgent | unknown;\n    let bigestParticipation: number = 0;\n\n    for (let a = 0; a < this.members.length; a++) {\n      const controllerCandidate = this.members[a];\n\n      if (!controllerCandidate.participation) {\n        throw new Error(\n          \"Unable to known the board controller: not all participations are known\"\n        );\n      }\n\n      const participation: number = controllerCandidate.participation as number;\n\n      if (!controller || bigestParticipation < participation) {\n        controller = controllerCandidate.agent;\n        bigestParticipation = participation;\n      } \n    }\n\n    return controller as BusinessAgent;\n  }\n}\n"],"mappings":";;;;;AAAA;AAKO,IAAM,gBAAN,MAAoB;AAAA,EACzB,UAAuE,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxE,UAAU,WAA0B,eAA8B;AAChE,SAAK,QAAQ,KAAK,EAAE,OAAO,WAAW,cAAc,CAAC;AAAA,EACvD;AAAA,EAEA,gBAA+B;AAC7B,QAAI;AACJ,QAAI,sBAA8B;AAElC,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,KAAK;AAC5C,YAAM,sBAAsB,KAAK,QAAQ,CAAC;AAE1C,UAAI,CAAC,oBAAoB,eAAe;AACtC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,YAAM,gBAAwB,oBAAoB;AAElD,UAAI,CAAC,cAAc,sBAAsB,eAAe;AACtD,qBAAa,oBAAoB;AACjC,8BAAsB;AAAA,MACxB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}