import { Service } from 'egg';
import { STATUS } from '@consts';
import { SearchLogParam, SearchUserLogParam } from '@domain/backEndField/search';
import { GMRecordModel } from '@db/GMRecord';
import { UserLogModel } from '@db/UserLog';
import { UserGachaRecModel } from '@db/UserGachaRec';

/**
 * Test Service
 */
export default class Log extends Service {

  /**
   * 获取后台操作日志
   */
  public async getGmLog(page: number, pageSize: number, form: SearchLogParam) {
    const {ctx} = this;

    let list = await GMRecordModel.findByCondition(page, pageSize, form);
    return ctx.service.utils.resResult(STATUS.SUCCESS, { list });
  }

  /**
   * 获取玩家日志
   */
  public async getUserLog(page: number, pageSize: number, form: SearchUserLogParam) {
    const {ctx} = this;

    let list = await UserLogModel.findByCondition(page, pageSize, form);
    return ctx.service.utils.resResult(STATUS.SUCCESS, { list: list.map(cur => ({...cur, env: ctx.app.config.realEnv})) });
  }

  /**
   * 获取抽卡日志
   */
   public async getGachaLog(page: number, pageSize: number, form: SearchUserLogParam) {
    const {ctx} = this;

    let list = await UserGachaRecModel.findByCondition(page, pageSize, form);
    return ctx.service.utils.resResult(STATUS.SUCCESS, { list: list.map(cur => ({...cur, env: ctx.app.config.realEnv})) });
  }
}
