package com.kexue.skills.controller;

import com.github.pagehelper.PageInfo;
import com.kexue.skills.annotation.RequireAuth;
import com.kexue.skills.common.CommonResult;
import com.kexue.skills.entity.PackageConfig;
import com.kexue.skills.entity.base.IdDto;
import com.kexue.skills.entity.dto.PackageConfigDto;
import com.kexue.skills.service.PackageConfigService;
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;

/**
 * (PackageConfig)表控制层
 *
 * @author 系统生成
 * @since 2026-04-11
 */
@RestController
@RequestMapping("api/packageConfig")
@Tag(name = "套餐配置管理 Api")
@CrossOrigin(origins = "*")
public class PackageConfigController {
    /**
     * 服务对象
     */
    @Resource
    private PackageConfigService packageConfigService;

    /**
     * 分页查询
     *
     * @param queryDto 筛选条件
     * @return 查询结果
     */
    @PostMapping("/getPageList")
    @Operation(summary = "查询分页列表", description = "查询分页列表")
    public CommonResult<PageInfo<PackageConfig>> getPageList(@RequestBody PackageConfigDto queryDto) {
        return CommonResult.success(packageConfigService.getPageList(queryDto));
    }

    /**
     * 查询列表
     *
     * @param queryDto 筛选条件
     * @return 查询结果
     */
    @PostMapping("/getList")
    @Operation(summary = "查询列表", description = "查询列表")
    public CommonResult<PageInfo<PackageConfig>> getList(@RequestBody PackageConfigDto queryDto) {
        return CommonResult.success(new PageInfo<>(packageConfigService.getList(queryDto)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("queryById/{id}")
    @Operation(summary = "通过ID查询套餐", description = "通过ID查询套餐")
    public CommonResult<PackageConfig> queryById(@PathVariable("id") Long id) {
        return CommonResult.success(packageConfigService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param packageConfig 实体
     * @return 新增结果
     */
    @PostMapping("/insert")
    @Operation(summary = "新增套餐", description = "新增套餐")
    @RequireAuth
    public CommonResult<PackageConfig> insert(@RequestBody PackageConfig packageConfig) {
        return CommonResult.success(packageConfigService.insert(packageConfig));
    }

    /**
     * 编辑数据
     *
     * @param packageConfig 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    @Operation(summary = "更新套餐", description = "更新套餐")
    @RequireAuth
    public CommonResult<PackageConfig> update(@RequestBody PackageConfig packageConfig) {
        return CommonResult.success(packageConfigService.update(packageConfig));
    }

    /**
     * 通过主键逻辑删除
     *
     * @param idDto 主键
     * @return 删除数据
     */
    @PostMapping("/logicDeleteById")
    @Operation(summary = "逻辑删除套餐", description = "逻辑删除套餐")
    @RequireAuth
    public CommonResult<Boolean> logicDeleteById(@RequestBody IdDto idDto) {
        return CommonResult.success(packageConfigService.logicDeleteById(idDto.getId(), "admin") > 0);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除数据
     */
    @PostMapping("deleteById/{id}")
    @Operation(summary = "物理删除套餐", description = "物理删除套餐")
    @RequireAuth
    public CommonResult<Boolean> deleteById(@PathVariable("id") Long id) {
        return CommonResult.success(packageConfigService.deleteById(id) > 0);
    }

}
