import helper from 'src/Utils/helper';
import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  LoginEntity,
  SysUserSearchEntity,
  UpdatePasswordEntity,
  SysUserEntity
} from './model/login';
const pathName = 'User/';

class LoginApi {
  login = (val?: Login.LoginFormData) => {
    return request.post('auth/login', val);
  };

  getMenus = () => {
    return request.get('auth/getMenus');
  };

  getAuthInfo = () => {
    return request.get('auth/getAuthInfo');
  };

  // 获取用户信息分页
  getSysUserPageList = (val: Pagination<SysUserSearchEntity>) => {
    let format = `?page=${val.page}&size=${val.rowsPerPage}`;
    if (val.data.userName) {
      format += `&userName=${val.data.userName}`;
    }
    if (val.data.activated != undefined && val.data.activated != null) {
      format += `&activated=${val.data.activated}`;
    }
    return request.get(`${pathName}GetSysUserPageList${format}`);
  };

  // 登录
  Login = (val: LoginEntity) => {
    const format = helper.params(val);
    return request.post(`${pathName}Lgoin${format}`);
  };

  // 修改用户密码
  updatePassword = (val: UpdatePasswordEntity) => {
    const format = helper.params(val);
    return request.post(`${pathName}UpdatePassword${format}`);
  };

  // 获取用户明细
  getSysUserDetail = (id: any) => {
    return request.get(`${pathName}GetSysUserDetail?id=${id}`);
  };

  // 添加
  add = (val: SysUserEntity) => {
    return request.post(`${pathName}AddSysUser`, val);
  };

  // 修改
  edit = (val: SysUserEntity) => {
    return request.post(`${pathName}UpdateSysUser`, val);
  };

  // 删除
  delete = (id: any) => {
    return request.post(`${pathName}DeleteSysUser?id=${id}`);
  };
}

const loginApi = new LoginApi();
export { loginApi };
