package com.kym.admin.controller;

import com.kym.common.R;
import com.kym.common.annotation.SysLog;
import com.kym.entity.admin.queryParams.ActivityQueryParam;
import com.kym.entity.common.PageParams;
import com.kym.entity.admin.vo.ActivityVo;
import com.kym.service.admin.ActivityService;
import com.kym.service.admin.RechargeRightsService;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2023-10-18
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {

    private final ActivityService activityService;

    private final RechargeRightsService rechargeRightsService;

    public ActivityController(ActivityService activityService, RechargeRightsService rechargeRightsService) {
        this.activityService = activityService;
        this.rechargeRightsService = rechargeRightsService;
    }


    @SysLog(value = "新增活动", ignoreParams = true)
    @PostMapping("/add")
    R<?> createActivity(@RequestBody ActivityVo activityVo) {
        activityService.createActivity(activityVo);
        return R.success();
    }

    @SysLog("活动列表")
    @GetMapping
    R<?> listActivity(@ModelAttribute ActivityQueryParam params) {
        return R.success(activityService.listActivity(params));
    }

    @SysLog("活动详情")
    @GetMapping("/{activityId}")
    R<?> activityDetail(@PathVariable("activityId") String activityId) {
        return R.success(activityService.activityDetail(activityId));
    }

    @SysLog("终止活动")
    @GetMapping("/terminateActivity/{activityId}")
    R<?> terminateActivity(@PathVariable("activityId") String activityId) {
        activityService.terminateActivity(activityId);
        return R.success();
    }

    /**
     * 充值权益列表
     *
     * @param pageParams
     * @param activityId
     * @return
     */
    @GetMapping("/listRechargeRight")
    R<?> listRechargeRight(@ModelAttribute PageParams pageParams, @RequestParam(value = "activityId", required = false) String activityId) {
        return R.success(rechargeRightsService.listRechargeRight(pageParams, activityId));
    }

}
