import 'package:dio/dio.dart';

/// 登录请求类
class LoginReq {
  String username; // 用户名
  String password; // 密码

  LoginReq(username, password) {
    this.username = username;
    this.password = password;
  }

  LoginReq.fromJson(Map<String, dynamic> json)
      : username = json['username'],
        password = json['password'];

  Map<String, dynamic> toJson() => {
        'username': username,
        'password': password,
      };

  FormData toFormData() {
    return FormData.from({'username': username, 'password': password});
  }

  @override
  String toString() {
    return '{' +
        " \"username\":\"" +
        username +
        "\"" +
        ", \"password\":\"" +
        password +
        "\"" +
        '}';
  }
}

/// 用户Model，user/info接口返回对象
class UserModel {
  String name; // 姓名
  String id; // id
  String username; // 账户
  String phone; // 手机号

  UserModel.fromJson(Map<String, dynamic> json)
      : name = json['name'],
        id = json['id'],
        username = json['account'],
        phone = json['phone'];

  Map<String, dynamic> toJson() => {
        'name': name,
        'id': id,
        'username': username,
        'phone': phone,
      };

  @override
  String toString() {
    StringBuffer sb = new StringBuffer('{');
    sb.write(",\"name\":\"$name\"");
    sb.write(",\"id\":$id");
    sb.write(",\"username\":\"$username\"");
    sb.write(",\"phone\":\"$phone\"");
    sb.write('}');
    return sb.toString();
  }
}
