import { Controller } from 'egg';

export default class AccountController extends Controller {

  public async deviceLogin() {
    const { ctx } = this;
    const { token, isGuest, deviceId, platform, pkgName, serverType, getuiCID } = ctx.request.body;
    ctx.body = await ctx.service.auth.deviceLogin(isGuest, token, deviceId, platform, pkgName, serverType, getuiCID);
  }

  public async getSms() {
    const { ctx } = this;
    const { type, tel } = ctx.request.body;
    ctx.body = await ctx.service.auth.getSms(type, tel);
  }

  public async smsLogin() {
    const { ctx } = this;
    const { tel, code, platform, pkgName, serverType, deviceId, getuiCID } = ctx.request.body;
    ctx.body = await ctx.service.auth.smsLogin(tel, deviceId, code, platform, pkgName, serverType, getuiCID);
  }

  public async getSmsCode() {
    const { ctx } = this;
    const { tel } = ctx.request.query;
    ctx.body = await ctx.service.auth.getSmsCode(tel);
  }

  public async setPassword() {
    const { ctx } = this;
    const { password } = ctx.request.body;
    ctx.body = await ctx.service.auth.setPassword(password);
  }

  public async pwLogin() {
    const { ctx } = this;
    const { tel, deviceId, password, getuiCID } = ctx.request.body;
    ctx.body = await ctx.service.auth.pwLogin(tel, deviceId, password, getuiCID);
  }

  public async checkRole() {
    const { ctx } = this;
    const { serverId } = ctx.request.body;
    ctx.body = await ctx.service.auth.checkRole(serverId);
  }

  public async createRole() {
    const { ctx } = this;
    const { serverId, distinctId } = ctx.request.body;
    ctx.body = await ctx.service.auth.createRole(serverId, distinctId);
  }

  public async bind() {
    const { ctx } = this;
    const { tel, code } = ctx.request.body;
    ctx.body = await ctx.service.auth.bind(tel, code);
  }

  public async authentication() {
    const { ctx } = this;
    const { name, idNum } = ctx.request.body;
    ctx.body = await ctx.service.auth.authentication(name, idNum);
  }

  public async channelLogin() {
    const { ctx } = this;
    ctx.body = await ctx.service.auth.channelLogin(ctx.request.body);
  }

  public async deleteRole() {
    const { ctx } = this;
    const { roleId, magicWord } = ctx.request.body;
    ctx.body = await ctx.service.auth.deleteRole(roleId, magicWord);
  }
}
