import { Injectable } from '@angular/core';
import { Get, Post, requestDone } from '../http.decorators';
import { _BaseApi } from './_base';

@Injectable({ providedIn: 'root' })
export class UserApi extends _BaseApi {
  @Get('/user/my-detail')
  async getMyInfo(): Promise<Auth.User> {
    requestDone();
  }

  @Get('/user/detail', false, ['id'])
  async getUserDetailInfo(id: number): Promise<ResWrapper<Auth.User>> {
    requestDone();
  }

  @Post('/general/modify')
  async modifyMyInfo(data: Auth.ModifyUserInfo): Promise<void> {
    requestDone(data);
  }

  async getUserList(p: FormSearchParams<Auth.User>) {
    return this.http.get<Auth.UserList>('/user/list', p);
  }
  async getAllUserByCompany(company: string) {
    return this.http.get<Auth.User[]>('/user/list-all', { company });
  }
  async addUser(p: Partial<Auth.UserRequestParams>) {
    return this.http.post<void>('/user/create', p);
  }
  async updateUser(p: Partial<Auth.UserRequestParams>) {
    return this.http.post<void>('/user/update', p);
  }
  async updateUserRoles(p: Partial<Auth.User>) {
    return this.http.post<void>('/user/set-roles', p);
  }
  async deleteUser(username: number | string) {
    return this.http.delete<void>('/user/remove', { username });
  }
  async deleteAllUser(ids: number[]) {
    return this.http.post<void>('/user/delete-all', { ids });
  }
}
