package com.liquidnet.service.slime.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.slime.dto.param.SlimeSponsorApplyParam;
import com.liquidnet.service.slime.dto.vo.SlimeSponsorsVo;
import com.liquidnet.service.slime.dto.vo.SlimeSponsorAppliesVo;
import com.liquidnet.service.slime.service.ISlimeSponsorAppliesService;
import com.liquidnet.service.slime.service.ISlimeSponsorsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * <p>
 * 主办 前端控制器
 * </p>
 *
 * @author liquidnet
 * @since 2021-11-01
 */
@ApiSupport(order = 10002)
@Api(tags = "主办")
@Slf4j
@Validated
@RestController
@RequestMapping("sponsors")
public class SlimeSponsorsController {

    @Autowired
    ISlimeSponsorsService slimeSponsorsService;

    @Autowired
    ISlimeSponsorAppliesService slimeSponsorAppliesService;

    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "主办搜索")
    @GetMapping("search")
    public ResponseDto<PagedResult<SlimeSponsorsVo>> search(@RequestParam(required = true) @NotBlank(message = "搜索内容不能为空") String name,
                                                            @RequestParam(defaultValue = "1", required = false) int page,
                                                            @RequestParam(defaultValue = "10", required = false) int size) {
        return ResponseDto.success(slimeSponsorsService.search(name, page, size));
    }

    @ApiOperationSupport(order = 11)
    @ApiOperation(value = "申请主办")
    @PostMapping("apply")
    public ResponseDto<Object> apply(@Valid @RequestBody SlimeSponsorApplyParam parameter) {
        String currentUid = CurrentUtil.getCurrentUid();

        return ResponseDto.success(slimeSponsorAppliesService.apply(currentUid, parameter));
    }

    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "申请主办驳回后删除")
    @PostMapping("apply/del")
    public ResponseDto<Object> applyDel(@RequestParam(required = true) String sponsorApplyId) {
        String currentUid = CurrentUtil.getCurrentUid();

        slimeSponsorAppliesService.applyDel(currentUid, sponsorApplyId);

        return ResponseDto.success();
    }

    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "申请主办详情")
    @PostMapping("apply/info")
    public ResponseDto<SlimeSponsorAppliesVo> applyInfo(@RequestParam(required = true) @NotBlank(message = "主办申请ID不能为空") String sponsorApplyId) {
        String currentUid = CurrentUtil.getCurrentUid();

        return ResponseDto.success(slimeSponsorAppliesService.applyInfo(currentUid, sponsorApplyId));
    }


    @ApiOperationSupport(order = 20)
    @ApiOperation(value = "主办详情")
    @GetMapping("info")
    public ResponseDto<SlimeSponsorsVo> info(@RequestParam(required = true) @NotBlank(message = "主办ID不能为空") String sponsorId) {
        String currentUid = CurrentUtil.getCurrentUid();

        return ResponseDto.success(slimeSponsorsService.sponsorInfo(currentUid, sponsorId));
    }
}
