package com.mall.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;
import com.mall.order.domain.dto.OrderSettingDto;
import com.mall.order.domain.entity.OrderSetting;
import com.mall.order.domain.vo.OrderSettingVo;
import com.mall.order.service.OrderSettingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单配置信息 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 18:54:06
 */
@Tag(name = "订单配置信息", description = "订单配置信息相关接口")
@RestController
@RequestMapping("/api/order/order-setting")
@RequiredArgsConstructor
public class OrderSettingController {

    private final OrderSettingService orderSettingService;

    @Operation(summary = "分页查询订单配置信息", description = "分页订单配置信息")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<OrderSettingVo>> getOrderSettingPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            OrderSettingDto dto) {
        Page<OrderSetting> pageParams = new Page<>(page, limit);
        PageResult<OrderSettingVo> pageResult = orderSettingService.getOrderSettingPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加订单配置信息", description = "添加订单配置信息")
    @PostMapping()
    public Result<String> addOrderSetting(@Valid @RequestBody OrderSettingDto dto) {
        orderSettingService.addOrderSetting(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新订单配置信息", description = "更新订单配置信息")
    @PutMapping()
    public Result<String> updateOrderSetting(@Valid @RequestBody OrderSettingDto dto) {
        orderSettingService.updateOrderSetting(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除订单配置信息", description = "删除订单配置信息")
    @DeleteMapping()
    public Result<String> deleteOrderSetting(@RequestBody List<Long> ids) {
        orderSettingService.deleteOrderSetting(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}