package cn.reghao.tnb.content.app.mall.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.content.app.mall.model.po.Delivery;
import cn.reghao.tnb.content.app.mall.service.DeliveryService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-04-26 11:45:14
 */
@Tag(name = "收货地址接口")
@RestController
@RequestMapping("/api/mall/delivery")
public class DeliveryController {
    private final DeliveryService deliveryService;

    public DeliveryController(DeliveryService deliveryService) {
        this.deliveryService = deliveryService;
    }

    @Operation(summary = "添加收获地址", description = "N")
    @AuthUser
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addDeliveryAddress() {
        return WebResult.success();
    }

    @Operation(summary = "删除收获地址", description = "N")
    @AuthUser
    @DeleteMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public String deleteDeliveryAddress() {
        return WebResult.success();
    }

    @Operation(summary = "获取用户的收获地址列表", description = "N")
    @AuthUser
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getDeliveryAddress() {
        long loginUser = UserContext.getUserId();
        List<Delivery> list = deliveryService.getUserAddresses(loginUser);
        return WebResult.success(list);
    }
}
