/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.guosen.helpRecord.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.guosen.activity.service.IActivityService;
import org.springblade.modules.guosen.helpRecord.dto.HelpRecordDTO;
import org.springblade.modules.guosen.helpRecord.entity.HelpRecord;
import org.springblade.modules.guosen.helpRecord.service.IHelpRecordService;
import org.springblade.modules.guosen.helpRecord.vo.HelpRecordVO;
import org.springblade.modules.guosen.helpRecord.wrapper.HelpRecordWrapper;
import org.springblade.modules.guosen.loginUser.service.ILoginUserService;
import org.springblade.modules.guosen.present.service.IPresentService;
import org.springblade.modules.guosen.production.service.IProductionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *  控制器
 *
 * @author BladeX
 * @since 2021-06-17
 */
@RestController
@AllArgsConstructor
@RequestMapping("cyzh-helpRecord/helprecord")
@Api(value = "", tags = "接口")
public class HelpRecordController extends BladeController {

	private final IHelpRecordService helpRecordService;

	@Resource
	private ILoginUserService loginUserService;
	@Resource
	private IActivityService activityService;
	@Resource
	private IProductionService productionService;
	@Resource
	private IPresentService presentService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入helpRecord")
	public R<HelpRecordVO> detail(HelpRecord helpRecord) {
		HelpRecord detail = helpRecordService.getOne(Condition.getQueryWrapper(helpRecord));
		return R.data(HelpRecordWrapper.build(loginUserService,activityService,productionService,presentService).entityVO(detail));
	}

	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入helpRecord")
	public R<IPage<HelpRecordVO>> list(HelpRecord helpRecord, Query query) {
		IPage<HelpRecord> pages = helpRecordService.page(Condition.getPage(query), Condition.getQueryWrapper(helpRecord).lambda().orderByDesc(HelpRecord::getCreateTime));
		return R.data(HelpRecordWrapper.build(loginUserService,activityService,productionService,presentService).pageVO(pages));
	}

	/**
	 * 分页
	 */
	@GetMapping("/list2")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入helpRecord")
	public R<IPage<HelpRecordVO>> list2(HelpRecord helpRecord, Query query) {
		IPage<HelpRecord> pages = helpRecordService.page(Condition.getPage(query), Condition.getQueryWrapper(helpRecord).lambda().orderByDesc(HelpRecord::getCreateTime));
		return R.data(HelpRecordWrapper.build(loginUserService).pageVO(pages));
	}


	/**
	 * 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入helpRecord")
	public R<IPage<HelpRecordVO>> page(HelpRecordVO helpRecord, Query query) {
		IPage<HelpRecordVO> pages = helpRecordService.selectHelpRecordPage(Condition.getPage(query), helpRecord);
		return R.data(pages);
	}

	/**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入helpRecord")
	public R save(@Valid @RequestBody HelpRecord helpRecord) {
		return R.status(helpRecordService.save(helpRecord));
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入helpRecord")
	public R update(@Valid @RequestBody HelpRecord helpRecord) {
		return R.status(helpRecordService.updateById(helpRecord));
	}

	/**
	 * 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入helpRecord")
	public R submit(@Valid @RequestBody HelpRecord helpRecord) {
		return R.status(helpRecordService.saveOrUpdate(helpRecord));
	}


	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(helpRecordService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 打榜，作品打榜和作者打榜
	 * 1：作品打榜需要传入的参数
	 * activityId 活动id
	 * productId 作品id
	 * senderId 助力人的id
	 * receiverId 被助力人的id
	 * type 0
	 * 2：作者打榜需要传入的参数
	 * activityId 活动id
	 * senderId 助力人的id
	 * receiverId 被助力人的id
	 * type 2
	 */
	@PostMapping("/doHit")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "打榜", notes = "传入hitRecord")
	public R doHit(@Valid @RequestBody HelpRecordDTO helpRecordDTO) {
		return helpRecordService.doHit(helpRecordDTO);
	}

	/**
	 * 自定义分页带头像和昵称
	 * 1：传入receiverId可查询热力明细，就是别人给我助力的热力
	 * 2：传入senderId 可查询我的助力。就是我给别人的热力
	 * 3：传入productId 可查询该作品的助力情况
	 * 4: XXX[暂时没做]传入receiverId ，且type 为2或3 可查询 给作者的助力
	 */
	@GetMapping("/selectHelpRecordVoPage")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入helpRecord")
	public R<IPage<HelpRecordVO>> selectHelpRecordVoPage(HelpRecordVO helpRecordVO, Query query) {
		IPage<HelpRecordVO> pages = helpRecordService.selectHelpRecordVoPage(Condition.getPage(query), helpRecordVO);
		return R.data(pages);
	}

	/**
	 * 打赏，作品打赏和作者打赏
	 * 1：作品打赏需要传入的参数
	 * activityId 活动id
	 * productId 作品id
	 * presentId 礼物id
	 * senderId 助力人的id
	 * receiverId 被助力人的id
	 * type 1
	 * count 打赏的礼物数量
	 * 2：作者打赏需要传入的参数
	 * activityId 活动id
	 * presentId 礼物id
	 * senderId 助力人的id
	 * receiverId 被助力人的id
	 * type 3
	 * count 打赏的礼物数量
	 */
	@PostMapping("/doReward")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "打赏", notes = "传入helpRecordDTO")
	public R doReward(@Valid @RequestBody HelpRecordDTO helpRecordDTO) {

		return helpRecordService.doReward(helpRecordDTO);
	}



}
