package org.example.petshopdesktop.api.endpoints;

import org.example.petshopdesktop.api.ApiClient;
import org.example.petshopdesktop.api.dto.auth.AvatarUploadResponse;
import org.example.petshopdesktop.api.dto.auth.UserInfoResponse;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class AuthApi {
    private static final AuthApi INSTANCE = new AuthApi();
    private final ApiClient apiClient;

    private AuthApi() {
        this.apiClient = ApiClient.getInstance();
    }

    public static AuthApi getInstance() {
        return INSTANCE;
    }

    public UserInfoResponse getCurrentUser() throws Exception {
        return apiClient.get("/api/v1/auth/me", UserInfoResponse.class);
    }

    public AvatarUploadResponse uploadAvatar(Path filePath) throws Exception {
        return apiClient.postMultipart("/api/v1/auth/me/avatar", "avatar", filePath, AvatarUploadResponse.class);
    }

    public byte[] getMyAvatarFile() throws Exception {
        return apiClient.getBytes("/api/v1/auth/me/avatar/file");
    }

    public void deleteAvatar() throws Exception {
        apiClient.delete("/api/v1/auth/me/avatar");
    }

    public void forgotPassword(String usernameOrEmail) throws Exception {
        Map<String, String> body = new HashMap<>();
        body.put("usernameOrEmail", usernameOrEmail);
        apiClient.post("/api/v1/auth/forgot-password", body, Object.class);
    }
}
