import apiClient, { saveAccessToken, removeTokens } from '../common/axios-instance.js';

const signService = {

    signIn: async (username, password) => {
        const response = await apiClient.post('/sign-in', { username, password });
        const accessToken = response.headers['authorization'].split(' ')[1];
        saveAccessToken(accessToken);
        return response.data;
    },

    signOut: async () => {
        await apiClient.post('/sign-out');
        removeTokens();
    },

    signUp: async (params) => {
        const response = await apiClient.post('/api/user/sign-up', params);
        return response.data;
    },

    isConflictUserId: async (userId) => {
        const response = await apiClient.get(`/api/user/conflict/${userId}`);
        return response.data.data;
    },

    changePassword: async (userId, newPassword) => {
        const response = await apiClient.post('/api/user/change-password', { userId, newPassword });
        return response.data.data;
    }

};

export default signService;