package com.smyhub.store.mengyastorebackendjava.controller;

import com.smyhub.store.mengyastorebackendjava.dto.response.ApiResponse;
import com.smyhub.store.mengyastorebackendjava.dto.response.OrderResponse;
import com.smyhub.store.mengyastorebackendjava.security.CurrentUserHolder;
import com.smyhub.store.mengyastorebackendjava.service.OrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class UserOrderController {

    private final OrderService orderService;

    @GetMapping("/orders")
    public ResponseEntity<ApiResponse<List<OrderResponse>>> myOrders() {
        String account = CurrentUserHolder.get().getAccount();
        return ResponseEntity.ok(ApiResponse.ok(orderService.getMyOrders(account)));
    }
}
