import httpClient from '@/api/httpClient';
import { API_URLS } from '@/api/URLs';
import { ProductBody, ProductResponse } from '@/screens/home/lib/types';
import { AxiosResponse } from 'axios';
import {
  ExployeesResponse,
  MyAdsData,
  MyAdsDataRes,
  MyBonusesData,
  UserInfoResponseData,
} from './type';

export const user_api = {
  async getMe(): Promise<AxiosResponse<UserInfoResponseData>> {
    const res = await httpClient.get(API_URLS.Get_Me);
    return res;
  },

  async updateMe(body: {
    first_name: string;
    industries: {
      id: number;
      name: string;
      code: string;
      external_id: null | number;
      level: number;
      is_leaf: boolean;
      icon_name: null | string;
      parent: {
        id: number;
        name: string;
        code: string;
      };
    }[];
    person_type: 'employee' | 'legal_entity' | 'ytt' | 'band';
    phone: string;
    activate_types: number[];
  }) {
    const res = await httpClient.patch(API_URLS.User_Update, body);
    return res;
  },

  async employess(params: {
    page: number;
    page_size: number;
  }): Promise<AxiosResponse<ExployeesResponse>> {
    const res = await httpClient.get(API_URLS.Employee_List, { params });
    return res;
  },

  async create_employee(body: { first_name: string; last_name: string; phone: string }) {
    const res = await httpClient.post(API_URLS.Employee_List, body);
    return res;
  },

  async my_ads(params: { page: number; page_size: number }): Promise<AxiosResponse<MyAdsData>> {
    const res = await httpClient.get(API_URLS.My_Ads, { params });
    return res;
  },

  async my_ads_detail(id: number): Promise<AxiosResponse<{ status: boolean; data: MyAdsDataRes }>> {
    const res = await httpClient.get(API_URLS.My_Ads_Detail(id));
    return res;
  },

  async my_bonuses(params: {
    page: number;
    page_size: number;
  }): Promise<AxiosResponse<MyBonusesData>> {
    const res = await httpClient.get(API_URLS.My_Bonuses, { params });
    return res;
  },

  async my_sevices(params: {
    page: number;
    page_size: number;
    my: boolean;
  }): Promise<AxiosResponse<ProductBody>> {
    const res = await httpClient.get(API_URLS.Get_Products, { params });
    return res;
  },

  async add_service(body: FormData) {
    const res = await httpClient.post(API_URLS.Get_Products, body, {
      headers: { 'Content-Type': 'multipart/form-data' },
    });
    return res;
  },

  async update_service({ body, id }: { body: FormData; id: number }) {
    const res = await httpClient.patch(API_URLS.Detail_Products(id), body, {
      headers: { 'Content-Type': 'multipart/form-data' },
    });
    return res;
  },

  async delete_service(id: number) {
    const res = await httpClient.delete(API_URLS.Delete_Products(id));
    return res;
  },

  async detail_service(
    id: number
  ): Promise<AxiosResponse<{ status: boolean; data: ProductResponse }>> {
    const res = await httpClient.get(API_URLS.Detail_Products(id));
    return res;
  },
};
