package com.yida.data.school.visitor.controller.out;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.visitor.EduVisitorRecord;
import com.yida.data.school.visitor.service.EduVisitorRecordService;
import com.yida.data.school.vo.visitor.ListVisitorRecordVO;
import com.yida.data.school.vo.visitor.PassCodeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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;

@Api(tags = "访客管理-访客记录 (外部使用不鉴权)")
@RestController
@RequestMapping("/out/visitor/record")
@RequiredArgsConstructor
public class OutEduVisitorRecordController {

    private final EduVisitorRecordService eduVisitorRecordService;

    @ApiOperation("根据邀请码查询详情")
    @GetMapping("/getInfo")
    public ResultBean getInfo(@ApiParam("邀请码") String inviteCode) {
        return ResultBean.buildSuccess(eduVisitorRecordService.getInfoByInviteCode(inviteCode));
    }

    @ApiOperation("查询邀请码是否有效(0-有效未使用，1-已使用，2-不存在)")
    @GetMapping("/checkInviteCode")
    public ResultBean<Integer> checkInviteCode(@ApiParam("邀请码") String inviteCode) {
        return ResultBean.buildSuccess(eduVisitorRecordService.checkInviteCode(inviteCode));
    }

    @ApiOperation("提交访问申请")
    @PostMapping("/commitVisitRequest")
    public ResultBean<ListVisitorRecordVO> commitVisitRequest(@RequestBody @Validated EduVisitorRecord visitorRecord) {
        return ResultBean.buildSuccess(eduVisitorRecordService.commitVisitRequest(visitorRecord));
    }

    @ApiOperation("获取访问码")
    @GetMapping("/getPassQr")
    public ResultBean<PassCodeVO> getPassQr(@ApiParam("邀请码") String inviteCode) {
        return ResultBean.buildSuccess(eduVisitorRecordService.getPassQr(inviteCode));
    }
}
