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.SlimeFieldApplyParam;
import com.liquidnet.service.slime.dto.vo.SlimeFieldAppliesVo;
import com.liquidnet.service.slime.dto.vo.SlimeFieldCheckersVo;
import com.liquidnet.service.slime.dto.vo.SlimeFieldsDetailsVo;
import com.liquidnet.service.slime.dto.vo.SlimeFieldsVo;
import com.liquidnet.service.slime.service.ISlimeFieldAppliesService;
import com.liquidnet.service.slime.service.ISlimeFieldsService;
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;
import java.util.List;

/**
 * <p>
 * 场地 前端控制器
 * </p>
 *
 * @author liquidnet
 * @since 2021-11-01
 */
@ApiSupport(order = 10001)
@Api(tags = "场地")
@Slf4j
@Validated
@RestController
@RequestMapping("fields")
public class SlimeFieldsController {

    @Autowired
    ISlimeFieldsService slimeFieldsService;

    @Autowired
    ISlimeFieldAppliesService slimeFieldAppliesService;

    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "场地搜索")
    @GetMapping("search")
    public ResponseDto<PagedResult<SlimeFieldsVo>> 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(slimeFieldsService.search(name, page, size));
    }

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

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

    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "申请场地驳回后删除")
    @PostMapping("apply/del")
    public ResponseDto<Object> applyDel(@RequestParam(required = true) @NotBlank(message = "场地申请ID不能为空") String fieldApplyId) {
        String currentUid = CurrentUtil.getCurrentUid();

        slimeFieldAppliesService.applyDel(currentUid, fieldApplyId);

        return ResponseDto.success();
    }

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

        return ResponseDto.success(slimeFieldAppliesService.applyInfo(currentUid, fieldApplyId));
    }


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

        return ResponseDto.success(slimeFieldsService.fieldInfo(currentUid, fieldId));
    }

    @ApiOperationSupport(order = 21)
    @ApiOperation(value = "场地更改是否审核演出")
    @PostMapping("editIsCheck")
    public ResponseDto<Object> editIsCheck(@RequestParam(required = true) @NotBlank(message = "场地ID不能为空") String fieldId,
                                           @RequestParam(required = true, defaultValue = "0") int isCheck) {
        String currentUid = CurrentUtil.getCurrentUid();

        slimeFieldsService.editIsCheck(currentUid, fieldId, isCheck);

        return ResponseDto.success();
    }


    @ApiOperationSupport(order = 30)
    @ApiOperation(value = "场地默认验票员列表")
    @GetMapping("checkers")
    public ResponseDto<List<SlimeFieldCheckersVo>> checkers(@RequestParam(required = true) @NotBlank(message = "场地ID不能为空") String fieldId) {
        String currentUid = CurrentUtil.getCurrentUid();

        return ResponseDto.success(slimeFieldsService.checkers(currentUid, fieldId));
    }

    @ApiOperationSupport(order = 31)
    @ApiOperation(value = "场地添加默认验票员")
    @PostMapping("checker/add")
    public ResponseDto<Object> checkerAdd(@RequestParam(required = true) @NotBlank(message = "场地ID不能为空") String fieldId,
                                          @RequestParam(required = true) @NotBlank(message = "uid不能为空") String uid,
                                          @RequestParam(required = true) @NotBlank(message = "手机号不能为空") String mobile,
                                          @RequestParam(required = true) @NotBlank(message = "姓名不能为空") String name) {
        String currentUid = CurrentUtil.getCurrentUid();

        return ResponseDto.success(slimeFieldsService.checkerAdd(currentUid, fieldId, uid, mobile, name));
    }

    @ApiOperationSupport(order = 32)
    @ApiOperation(value = "场地移除默认验票员")
    @PostMapping("checker/del")
    public ResponseDto<Object> checkerDel(@RequestParam(required = true) @NotBlank(message = "场地ID不能为空") String fieldId,
                                          @RequestParam(required = true) @NotBlank(message = "uid不能为空") String uid) {
        String currentUid = CurrentUtil.getCurrentUid();

        slimeFieldsService.checkerDel(currentUid, fieldId, uid);

        return ResponseDto.success();
    }


    @ApiOperationSupport(order = 34)
    @ApiOperation(value = "App场地详情")
    @GetMapping("app/details")
    public ResponseDto<SlimeFieldsDetailsVo> fieldDetails(@RequestParam(required = true) @NotBlank(message = "场地ID不能为空") String fieldId) {
        SlimeFieldsDetailsVo vo= slimeFieldsService.fieldDetails(fieldId);
        return ResponseDto.success(vo);
    }

}
