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.Logistics;
import cn.reghao.tnb.content.app.mall.model.po.LogisticsProgress;
import cn.reghao.tnb.content.app.mall.service.LogisticsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-09-19 09:06:30
 */
@Tag(name = "订单物流接口")
@RestController
@RequestMapping("/api/mall/logistics")
public class LogisticsController {
    private final LogisticsService logisticsService;

    public LogisticsController(LogisticsService logisticsService) {
        this.logisticsService = logisticsService;
    }

    @Operation(summary = "添加订单物流", description = "N")
    @AuthUser
    @PostMapping(value = "/order", produces = MediaType.APPLICATION_JSON_VALUE)
    public String putOrderLogistics(@RequestBody @Validated Logistics logistics) {
        logisticsService.putOrderLogistics(logistics);
        return WebResult.success();
    }

    @Operation(summary = "更新订单物流进度", description = "N")
    @AuthUser
    @PostMapping(value = "/progress", produces = MediaType.APPLICATION_JSON_VALUE)
    public String putOrderLogisticsProgress(@RequestBody @Validated LogisticsProgress logisticsProgress) {
        logisticsService.putOrderLogisticsProgress(logisticsProgress);
        return WebResult.success();
    }

    @Operation(summary = "获取订单物流进度", description = "N")
    @AuthUser
    @GetMapping(value = "/order/{orderId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getOrderLogistics(@PathVariable("orderId") Long orderId) {
        long userId = UserContext.getUserId();
        List<LogisticsProgress> list = logisticsService.getOrderLogistics(userId, orderId);
        return WebResult.success(list);
    }
}
