package com.liquidnet.service.adam.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.adam.dto.param.AdamCaomeiBadgeApplyParam;
import com.liquidnet.service.adam.dto.param.AdamCaomeiBadgeClaimParam;
import com.liquidnet.service.adam.dto.vo.AdamCaomeiBadgeApplyRecordUserVo;
import com.liquidnet.service.adam.service.IAdamCaomeiBadgeUserService;
import com.liquidnet.service.base.ResponseDto;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;

import javax.validation.Valid;
import java.util.List;

@ApiSupport(order = 10046)
@Api(tags = "草莓徽章（用户端）")
@Slf4j
@Validated
@RestController
@RequestMapping("caomei/badge")
public class AdamCaomeiBadgeUserController {

    @Autowired
    private IAdamCaomeiBadgeUserService adamCaomeiBadgeUserService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("认领徽章")
    @PostMapping("claim")
    public ResponseDto<List<String>> claim(@Valid @RequestBody AdamCaomeiBadgeClaimParam param) {
        String uid = CurrentUtil.getCurrentUid();
        return adamCaomeiBadgeUserService.claimBadges(param.getBadgeIds(), uid);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("补签记录列表")
    @GetMapping("apply/list")
    public ResponseDto<List<AdamCaomeiBadgeApplyRecordUserVo>> applyList() {
        String uid = CurrentUtil.getCurrentUid();
        return adamCaomeiBadgeUserService.getApplyRecords(uid);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("发起补签申请（驳回后可重新上传）")
    @PostMapping("apply")
    public ResponseDto<String> apply(@Valid @RequestBody AdamCaomeiBadgeApplyParam param) {
        String uid = CurrentUtil.getCurrentUid();
        return adamCaomeiBadgeUserService.applyBadge(param, uid);
    }
}
