const Mock = require('mockjs')

const PROTOCOLS = ['http', 'https', 'MQ', 'FTP']
const APITYPE = ['post', 'get', 'head', 'put', 'delete', 'options', 'trace', 'connect']
const DATATYPE = ['number', 'string', 'boolean', 'array', 'object']

module.exports = [
  {
    url: '/vue-admin-template/gateway/interface/list',
    type: 'get',
    response: config => {
      const data = Mock.mock({
        'items|11': [{
          'id|+1': 1,
          title: '@word(4, 10)',
          description: '/api/@word(10,20)/@word(5,10)',
          'protocol|1': PROTOCOLS,
          flag: '@boolean'
        }]
      })
      const items = data.items
      return {
        code: 20000,
        data: {
          items: items
        }
      }
    }
  },
  {
    url: '/vue-admin-template/gateway/limit/list',
    type: 'get',
    response: config => {
      const data = Mock.mock({
        'items|11': [{
          'id|+1': 1,
          title: '@word(4, 10)',
          visitTimes: '@natural(0, 30000)',
          visitDuration: '@natural(0, 100)',
          inBlacklist: '@boolean',
          flag: '@boolean'
        }]
      })
      const items = data.items
      return {
        code: 20000,
        data: {
          items: items
        }
      }
    }
  },
  {
    url: '/vue-admin-template/gateway/circuit-break/list',
    type: 'get',
    response: config => {
      const data = Mock.mock({
        'items|11': [{
          'id|+1': 1,
          title: '@word(4, 10)',
          circuitBreakDuration: '@natural(1, 100)',
          timeoutPeriod: '@natural(1, 100)',
          circuitBreakStandard: '@natural(1, 10)',
          interfaceBinding: '@natural(0, 10)',
          flag: '@boolean'
        }]
      })
      const items = data.items
      return {
        code: 20000,
        data: {
          items: items
        }
      }
    }
  },
  {
    url: '/vue-admin-template/gateway/document/list',
    type: 'get',
    response: config => {
      const data = Mock.mock({
        'items|11': [{
          'id|+1': 265912187337729,
          name: '/api/@word(10,20)/@word(5,10)',
          'protocol|1': PROTOCOLS,
          'type|1': APITYPE,
          time: '@datetime("yyyy/MM/dd HH:mm:ss")',
          method() {
            return this.name
          },
          description() {
            return this.name
          },
          params: {
            'input|0-2': [
              {
                name: '@word(4,10)',
                'type|1': DATATYPE,
                length: '@natural(1,100)',
                default() {
                  switch (this.type) {
                    case 'number':
                      return 1
                    case 'string':
                      return 'AAA'
                    case 'boolean':
                      return 'true'
                    case 'array':
                      return '[]'
                    case 'object':
                      return '{}'
                  }
                },
                reference: '无',
                required: '@boolean',
                superior: '',
                description: '@csentence'
              }
            ],
            'output|0-2': [
              {
                name: '@word(4,10)',
                'type|1': DATATYPE,
                length: '@natural(1,100)',
                default() {
                  switch (this.type) {
                    case 'number':
                      return 1
                    case 'string':
                      return 'AAA'
                    case 'boolean':
                      return 'true'
                    case 'array':
                      return '[]'
                    case 'object':
                      return '{}'
                  }
                },
                reference: '无',
                superior: '',
                description: '@csentence'
              }
            ]
          }
        }]
      })
      const items = data.items
      return {
        code: 20000,
        data: {
          items: items
        }
      }
    }
  }
]
