import { Controller } from 'egg';

export default class AccountController extends Controller {

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

  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 } = ctx.request.body;
    ctx.body = await ctx.service.auth.smsLogin(tel, deviceId, code, platform, pkgName, serverType);
  }

  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 } = ctx.request.body;
    ctx.body = await ctx.service.auth.pwLogin(tel, deviceId, password);
  }

  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 } = ctx.request.body;
    ctx.body = await ctx.service.auth.createRole(serverId);
  }

  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);
  }
}
