package com.hotwj.platform.operationManagement.hourPackagePurchase.controller;

import com.hotwj.platform.operationManagement.hourPackage.domain.bo.HotHourPackageBo;
import com.hotwj.platform.operationManagement.hourPackage.domain.vo.HotHourPackageVo;
import com.hotwj.platform.operationManagement.hourPackagePurchase.controller.vo.HotHourPackageWalletPurchaseReqVO;
import com.hotwj.platform.operationManagement.hourPackagePurchase.controller.vo.HotHourPackageWalletPurchaseRespVO;
import com.hotwj.platform.operationManagement.hourPackagePurchase.domain.bo.HotHourPackagePurchaseBo;
import com.hotwj.platform.operationManagement.hourPackagePurchase.domain.vo.HotHourPackagePurchaseVo;
import com.hotwj.platform.operationManagement.hourPackagePurchase.service.IHotHourPackagePurchaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学时套餐购买记录
 *
 * @author shihongwei
 * @date 2026-04-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/operationManagement/hourPackagePurchase")
@Tag(name = "学时套餐购买记录", description = "学时套餐购买记录管理")
public class HotHourPackagePurchaseController extends BaseController {

    private final IHotHourPackagePurchaseService hotHourPackagePurchaseService;

    /**
     * 查询学时套餐购买记录列表
     */
    //@SaCheckPermission("operationManagement:hourPackagePurchase:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询学时套餐购买记录列表")
    public TableDataInfo<HotHourPackagePurchaseVo> list(HotHourPackagePurchaseBo bo, PageQuery pageQuery) {
        return hotHourPackagePurchaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询当前登录用户可购买的学时套餐列表
     */
    @GetMapping("/available/list")
    @Operation(summary = "分页查询当前登录用户可购买的学时套餐列表")
    public TableDataInfo<HotHourPackageVo> availableList(HotHourPackageBo bo, PageQuery pageQuery) {
        return hotHourPackagePurchaseService.queryAvailablePageList(bo, pageQuery);
    }

    /**
     * 查询当前登录用户购买记录
     */
    @GetMapping("/current/list")
    @Operation(summary = "分页查询当前登录用户学时套餐购买记录")
    public TableDataInfo<HotHourPackagePurchaseVo> currentList(HotHourPackagePurchaseBo bo, PageQuery pageQuery) {
        return hotHourPackagePurchaseService.queryCurrentUserPageList(bo, pageQuery);
    }

    /**
     * 使用钱包余额购买学时套餐
     */
    @Log(title = "学时套餐购买记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/wallet/purchase")
    @Operation(summary = "使用钱包余额购买学时套餐")
    public R<HotHourPackageWalletPurchaseRespVO> walletPurchase(@Validated @RequestBody HotHourPackageWalletPurchaseReqVO reqVO) {
        return R.ok(hotHourPackagePurchaseService.purchaseByWallet(reqVO));
    }

    /**
     * 导出学时套餐购买记录列表
     */
    //@SaCheckPermission("operationManagement:hourPackagePurchase:export")
    @Log(title = "学时套餐购买记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出学时套餐购买记录列表")
    public void export(HotHourPackagePurchaseBo bo, HttpServletResponse response) {
        List<HotHourPackagePurchaseVo> list = hotHourPackagePurchaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "学时套餐购买记录", HotHourPackagePurchaseVo.class, response);
    }

    /**
     * 获取学时套餐购买记录详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("operationManagement:hourPackagePurchase:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取学时套餐购买记录详细信息")
    public R<HotHourPackagePurchaseVo> getInfo(@NotNull(message = "主键不能为空")
                                               @Parameter(name = "id", description = "主键", required = true, example = "1")
                                               @PathVariable Long id) {
        return R.ok(hotHourPackagePurchaseService.queryById(id));
    }

    /**
     * 新增学时套餐购买记录
     */
    //@SaCheckPermission("operationManagement:hourPackagePurchase:add")
    @Log(title = "学时套餐购买记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增学时套餐购买记录")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotHourPackagePurchaseBo bo) {
        return toAjax(hotHourPackagePurchaseService.insertByBo(bo));
    }

    /**
     * 修改学时套餐购买记录
     */
    //@SaCheckPermission("operationManagement:hourPackagePurchase:edit")
    @Log(title = "学时套餐购买记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改学时套餐购买记录")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotHourPackagePurchaseBo bo) {
        return toAjax(hotHourPackagePurchaseService.updateByBo(bo));
    }

    /**
     * 删除学时套餐购买记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("operationManagement:hourPackagePurchase:remove")
    @Log(title = "学时套餐购买记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除学时套餐购买记录")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotHourPackagePurchaseService.deleteWithValidByIds(List.of(ids), true));
    }
}
