import { request } from './index';

export type UserType = {
  id: number;
  mobile: string;
  name: string;
  isSuperUser: boolean;
};

export async function fetchUser(): Promise<UserType> {
  return await request(true, { url: '/users/user' });
}

type CreateUserBaseType = {
  mobile: string;
  firstName: string;
  lastName: string;
  gender: '' | 'M' | 'F';
};

export type CreateUserDataType = CreateUserBaseType & { password: string; authKey: string };
export type CreateUserReturnType = CreateUserBaseType & {
  id: number;
  name: string;
  token: string;
};

export async function createUser(data: CreateUserDataType): Promise<CreateUserReturnType> {
  return await request(false, {
    url: '/users/users',
    method: 'POST',
    data
  });
}
