import { MerchantEntity } from './../../entity/merchant';
import { Body, Get, Inject, Post, Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core';
import { MerchantService } from '../../service/merchant';
import { Utils } from '../../../../comm/utils';

@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'page', 'list'],
  entity: MerchantEntity,
  service: MerchantService,
  pageQueryOp: {
    keyWordLikeFields: ['mchId'],
    select: ['a.id', 'a.userId', 'a.name', 'a.mchId', 'a.email', 'a.status', 'a.whiteIp', 'a.remark', 'a.createTime', 'a.key', 'a.secret']
  },
  infoIgnoreProperty: ['fundPwd']
})
export class MerchantController extends BaseController {
  @Inject()
  utils: Utils;

  @Get('/createSecret', { summary: '生成谷歌验证码' })
  async createSecret() {
    return this.ok(this.utils.getGoogleSecret().base32);
  }

  @Post('/validSecret', { summary: '校验谷歌验证码' })
  async validSecret(@Body('secret') secret, @Body('code') code) {
    return this.ok(this.utils.validGoogleSecret(secret, code));
  }

}
