const Mock = require('mockjs')
const Random = Mock['Random']

const mockGeneration = 4 // primary
const mockGroups = [1, 2, 3, 4, 5, 6]
const mockPreferenceCount = 3 // 1 or 3 // 1志愿/3志愿

module.exports = [
  {
    url: '/mock/front/report/getElectiveStatus',
    type: 'get',
    response: config => {
      return {
        code: 200,
        msg: 'success',
        data: {
          year: 2021,
          roundId: 1,
          roundName: '第X次选科',
          groupIds: mockGroups.toString(),
          roundGroups: mockGroups.map(groupId => ({
            groupId: groupId,
            classCount: Random.integer(2, 6),
            personCount: function() {
              return this.classCount * 50
            },
            limitPerson: false,
            rankOut: false
          })),
          allMatched: false,
          currentGeneration: mockGeneration
        }
      }
    }
  },
  {
    url: '/mock/front/report/getElectiveSummary',
    type: 'get',
    response: config => {
      const results = []
      for (let generation = 1; generation <= mockGeneration; generation++) {
        const copyGeneration = generation
        switch (generation) {
          case 1:
            // primary
            const allPreferences = []
            for (let pref = 0; pref < mockPreferenceCount; pref++) {
              const preferences = []
              const groupDefines = [
                {
                  category: 'actualCount',
                  displayName: '实际人数',
                  values: mockGroups.map(groupId => ({
                    groupId: groupId,
                    value: Random.integer(120, 400),
                    color: '',
                    bold: false,
                    star: false,
                    queryCode: 'abc',
                    disabled: false
                  }))
                }
              ]
              const nonGroupDefines = [
                {
                  category: 'unfinishedCount',
                  displayName: '未完成人数',
                  values: [{
                    groupId: 0,
                    value: Random.integer(0, 10),
                    color: '',
                    bold: false,
                    star: false,
                    queryCode: 'abc',
                    disabled: false
                  }]
                }
              ]
              preferences.push(...groupDefines)
              preferences.push(...nonGroupDefines)
              allPreferences.push(preferences)
            }
            const primary = {
              roundId: 1,
              generation: copyGeneration,
              categories: allPreferences
            }
            results.push(primary)
            break
          default:
            const commonDefines = [
              {
                generations: [2],
                factory: () => [
                  {
                    category: 'indicateCount',
                    displayName: '指标',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'approvedCount',
                    displayName: '录取人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'adjustCount',
                    displayName: '调剂人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'matchedCount',
                    displayName: '可调剂人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'nonmatchedCount',
                    displayName: '不可调剂人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  }
                ]
              },
              {
                generations: [3, 5],
                factory: () => [
                  {
                    category: 'matchedApproved',
                    displayName: '可调剂已填人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'matchedRejected',
                    displayName: '可调剂已拒绝人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'matchedNonaction',
                    displayName: '可调剂未完成人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'nonmatchedApproved',
                    displayName: '不可调剂已填人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'nonmatchedRejected',
                    displayName: '不可调剂已拒绝人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'nonmatchedNonaction',
                    displayName: '不可调剂未完成人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  }
                ]
              },
              {
                generations: [4],
                factory: () => [
                  {
                    category: 'approvedCount',
                    displayName: '补录录取人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'forcedCount',
                    displayName: '调剂录取人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'matchedCount',
                    displayName: '可调剂人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'nonmatchedCount',
                    displayName: '不可调剂人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  }
                ]
              },
              {
                generations: [6],
                factory: () => [
                  {
                    category: 'approvedCount',
                    displayName: '补录录取人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  },
                  {
                    category: 'forcedCount',
                    displayName: '调剂录取人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  }
                ]
              },
              {
                generations: [7],
                factory: () => [
                  {
                    category: 'forcedCount',
                    displayName: '调剂录取人数',
                    values: mockGroups.map(groupId => ({
                      groupId: groupId,
                      value: Random.integer(120, 400),
                      color: '',
                      bold: false,
                      star: false,
                      queryCode: 'abc',
                      disabled: false
                    }))
                  }
                ]
              }
            ]
            const defines = commonDefines.find(d => d.generations.includes(generation))
            if (defines) {
              results.push({
                roundId: 1,
                generation: copyGeneration,
                categories: defines.factory()
              })
            }
            break
        }
      }

      return {
        code: 200,
        msg: 'success',
        data: results
      }
    }
  }
]
