package com.gxwebsoft.shop.controller;

import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.ShopSurchargeConfig;
import com.gxwebsoft.shop.param.ShopSurchargeConfigParam;
import com.gxwebsoft.shop.service.ShopSurchargeConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 步梯费用设置控制器
 *
 * @author xm
 * @since 2026-04-28 16:30:00
 */
@Tag(name = "步梯费用设置管理")
@RestController
@RequestMapping("/api/shop/shop-surcharge-config")
public class ShopSurchargeConfigController extends BaseController {
    @Resource
    private ShopSurchargeConfigService shopSurchargeConfigService;

//    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:list')")
    @Operation(summary = "分页查询步梯费用设置")
    @GetMapping("/page")
    public ApiResult<PageResult<ShopSurchargeConfig>> page(ShopSurchargeConfigParam param) {
        // 使用关联查询
        return success(shopSurchargeConfigService.pageRel(param));
    }

//    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:list')")
    @Operation(summary = "根据id查询步梯费用设置")
    @GetMapping("/{id}")
    public ApiResult<ShopSurchargeConfig> get(@PathVariable("id") Integer id) {
        // 使用关联查询
        return success(shopSurchargeConfigService.getByIdRel(id));
    }

//    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:list')")
    @Operation(summary = "根据类型查询步梯费用设置")
    @GetMapping("/getInfoByType")
    public ApiResult<ShopSurchargeConfig> getInfoByType(@RequestParam Integer type) {
        // 使用关联查询
        return success(shopSurchargeConfigService.getInfoByType(type));
    }

//    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:save')")
    @OperationLog
    @Operation(summary = "添加步梯费用设置")
    @PostMapping()
    public ApiResult<Integer> save(@RequestBody ShopSurchargeConfig shopSurchargeConfig) {
        return success(shopSurchargeConfigService.saveInfo(shopSurchargeConfig));
    }

//    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:update')")
    @OperationLog
    @Operation(summary = "修改步梯费用设置")
    @PutMapping()
    public ApiResult<Boolean> update(@RequestBody ShopSurchargeConfig shopSurchargeConfig) {
        return success(shopSurchargeConfigService.updateInfo(shopSurchargeConfig));
    }

//    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:update')")
    @OperationLog
    @Operation(summary = "修改步梯费用设置")
    @PutMapping("/updateStatus")
    public ApiResult<Boolean> updateStatus(@RequestParam("id") Integer id) {
        return success(shopSurchargeConfigService.updateStatus(id));
    }

    //    @PreAuthorize("hasAuthority('shop:shopSurchargeConfig:remove')")
    @OperationLog
    @Operation(summary = "删除步梯费用设置")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (shopSurchargeConfigService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
