package com.zioinfo.mall.wishlist;

import com.zioinfo.mall.common.ApiResponse;
import com.zioinfo.mall.wishlist.mapper.WishlistMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/** 찜 API — /api/mall/wishlist. 인증 고객. */
@RestController
@RequestMapping("/api/mall/wishlist")
@RequiredArgsConstructor
public class WishlistController {

    private final WishlistMapper mapper;

    @GetMapping
    public ApiResponse<List<Map<String, Object>>> list(Authentication auth) {
        return ApiResponse.ok(mapper.findByOwner(auth.getName()));
    }

    @PostMapping("/{productId}")
    public ApiResponse<String> add(@PathVariable Long productId, Authentication auth) {
        mapper.add(auth.getName(), productId);
        return ApiResponse.ok("added");
    }

    @DeleteMapping("/{productId}")
    public ApiResponse<String> remove(@PathVariable Long productId, Authentication auth) {
        mapper.remove(auth.getName(), productId);
        return ApiResponse.ok("removed");
    }
}
