import { Controller } from 'egg';
import { STATUS } from '@consts';

export default class GameController extends Controller {

  public async getServerEnv() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getServerEnv();
    return 
  }

  public async getServerListByEnv() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getServerListByEnv();
    return 
  }

  public async getServerList() {
    const { ctx } = this;
    const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;

    ctx.body = await ctx.service.game.getServerList(page, pageSize, sortField, sortOrder, form);
    return
  }

  public async getMaintenanceList() {
    const { ctx } = this;
    const {page, pageSize, sortField, sortOrder, form} = ctx.request.body;

    ctx.body = await ctx.service.game.getMaintenanceList(page, pageSize, sortField, sortOrder, form);
    return
  }

  public async updateMaintenance() {
    const { ctx } = this;
    const {values, marquee, notice, mail} = ctx.request.body;

    let goods = [];
    try{
      goods = JSON.parse(mail.goods);
    } catch(e) {
      ctx.body = ctx.service.utils.resResult(STATUS.GM_JSON_FORMAT_ERR);
      return
    }

    ctx.body = await ctx.service.game.updateMaintenance(
      {...values, startTime: new Date(values.startTime)}, 
      {...marquee, startTime: new Date(marquee.startTime), endTime: new Date(marquee.endTime)},
      {...notice, showStartTime: new Date(notice.showStartTime), showEndTime: new Date(notice.showEndTime), startTime: new Date(notice.startTime), endTime: new Date(notice.endTime)},
      {...mail, goods});
    return
  }

  public async getServerStategyList() {
    const { ctx } = this;
    const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;

    ctx.body = await ctx.service.game.getServerStategyList(page, pageSize, sortField, sortOrder, form);
    return
  }

  public async updateServerStategy() {
    const { ctx } = this;
    const { values } = ctx.request.body;

    ctx.body = await ctx.service.game.updateServerStategy(values);
    return
  }

  public async createNewServer() {
    const { ctx } = this;
    const { name, openTime, serverType, stategyId } = ctx.request.body;
    ctx.body = await ctx.service.game.createNewServer(name, openTime, serverType, stategyId);
    return
  }

  public async updateServer() {
    const { ctx } = this;
    const { id, name, groupName, serverStatus,  } = ctx.request.body;
    ctx.body = await ctx.service.game.updateServer(id, name, groupName, serverStatus);
    return
  }

  public async getNoticeList() {
    const { ctx } = this;
    const { page, pageSize, sortField, sortOrder, form  } = ctx.request.body;
    ctx.body = await ctx.service.game.getNoticeList(page, pageSize, sortField, sortOrder, form);
    return
  }

  public async updateNotice() {
    const {ctx} = this;
    const { id, values } = ctx.request.body;
    ctx.body = await ctx.service.game.updateNotice(id, values);
    return
  }

  public async delNotice() {
    const {ctx} = this;
    const { id } = ctx.request.body;
    ctx.body = await ctx.service.game.delNotice(id);
    return
  }

  public async getMarqueeList() {
    const { ctx } = this;
    const { page, pageSize, sortField, sortOrder, form  } = ctx.request.body;
    ctx.body = await ctx.service.game.getMarqueeList(page, pageSize, sortField, sortOrder, form);
    return
  }

  public async updateMarquee() {
    const { ctx } = this;
    const { code, values  } = ctx.request.body;
    ctx.body = await ctx.service.game.updateMarquee(code, values);
    return
  }

  public async getAccuse() {
    const { ctx } = this;
    const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
    ctx.body = await ctx.service.game.getAccuse(page, pageSize, sortField, sortOrder, form);
    return
  }

  public async getDicHero() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getDicHero();
    return 
  }

  public async getDicGoods() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getDicGoods();
    return 
  }

  public async getDicRMB() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getDicRmb();
    return
  }

  public async getDicActivityType() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getDicActivityType();
    return
  }

  public async getDicTaskType() {
    const { ctx } = this;
    ctx.body = await ctx.service.game.getDicTaskType();
    return
  }
}
