import type { AxiosResponse } from 'axios';
import axiosInstance from '../../utills/axiosInstance';
import axios from 'axios';

export const loginPost = async(data: {
    email: string
    password: string
}): Promise<AxiosResponse> => {
  return await axios.post('/api/v1/auth/login', data, {
    baseURL: process.env.BACKEND_URL,

    headers: {
      'Content-Type': 'application/json',
    },
  });
};

export const changePasswordByUser = async(id: number, data: any, authToken: string): Promise<any> => {
  const response = await axios.post(`/api/v1/auth/change-password-by-user/${id}`, data, {
    baseURL: process.env.BACKEND_URL,
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${authToken}`,
    },
  });
  if (response.status === 200) {
    return response.data;
  } else {
    throw new Error('Failed to update password!');
  }
};

export const logoutPost = async(): Promise<AxiosResponse> => {
  return await axiosInstance.post('/api/v1/auth/logout');
};

export const updateTrainingVideoStatus = async(data: {
    videoIndex: number
    progress?: number
    completed?: boolean
}): Promise<AxiosResponse> => {
  return await axiosInstance.patch('/api/v1/users/training-video-status', data);
};

export const getCurrentUserProfile = async(): Promise<AxiosResponse> => {
  return await axiosInstance.get('/api/v1/users/profile');
};
