package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.request.visit.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.visit.VisitRecordService;
import com.cool.store.vo.visit.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 拜访记录 前端控制器
 * </p>
 *
 * @author wangff
 * @since 2025/12/9
 */
@Api(tags = "拜访记录")
@RestController
@RequestMapping("/pc/visit/record")
@RequiredArgsConstructor
public class VisitRecordController {
    
    private final VisitRecordService visitRecordService;

    @ApiOperation("签到")
    @PostMapping("/signIn")
    public ResponseResult<String> signIn(@RequestBody @Validated VisitSignInRequest request) {
        return ResponseResult.success(visitRecordService.signIn(request));
    }

    @ApiOperation("签退")
    @PostMapping("/signOut")
    public ResponseResult<String> signOut(@RequestBody @Validated VisitSignOutRequest request) {
        return ResponseResult.success(visitRecordService.signOut(request));
    }

    @ApiOperation("编辑拜访记录")
    @PostMapping("/editRecord")
    public ResponseResult<Boolean> editRecord(@RequestBody @Validated VisitEditRequest request) {
        return ResponseResult.success(visitRecordService.editRecord(request));
    }

    @ApiOperation("拜访加盟商列表")
    @PostMapping("/partnerList")
    public ResponseResult<PageInfo<VisitPartnerListVO>> visitPartnerList(@RequestBody VisitPartnerQueryRequest request) {
        return ResponseResult.success(visitRecordService.visitPartnerList(request));
    }

    @ApiOperation("我的拜访加盟商列表")
    @PostMapping("/personPartnerList")
    public ResponseResult<PageInfo<VisitPartnerListVO>> personVisitPartnerList(@RequestBody VisitPartnerQueryRequest request) {
        request.setUserId(CurrentUserHolder.getUserId());
        request.setFilterAuth(true);
        return ResponseResult.success(visitRecordService.visitPartnerList(request));
    }

    @ApiOperation("查询拜访记录简单信息（h5使用）")
    @PostMapping("/simpleList")
    public ResponseResult<PageInfo<VisitRecordSimpleListVO>> recordSimpleList(@RequestBody VisitRecordSimpleQueryRequest request) {
        return ResponseResult.success(visitRecordService.recordSimpleList(request));
    }

    @ApiOperation("我的查询拜访记录简单信息（h5使用）")
    @PostMapping("/personSimpleList")
    public ResponseResult<PageInfo<VisitRecordSimpleListVO>> personRecordSimpleList(@RequestBody VisitRecordSimpleQueryRequest request) {
        request.setUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(visitRecordService.recordSimpleList(request));
    }

    @ApiOperation("获取拜访记录详情")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "id", value = "拜访记录id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<VisitRecordDetailVO> getDetail(@NotNull(message = "拜访记录id不能为空") Long id) {
        return ResponseResult.success(visitRecordService.getDetail(id));
    }

    @ApiOperation("取消拜访")
    @PostMapping("/cancel")
    public ResponseResult<Boolean> cancelVisit(@RequestBody @Validated VisitCancelRequest request) {
        return ResponseResult.success(visitRecordService.cancelVisit(request));
    }

    @ApiOperation("获取拜访记录列表")
    @PostMapping("/list")
    public ResponseResult<PageInfo<VisitRecordListVO>> recordList(@RequestBody VisitRecordQueryRequest request) {
        return ResponseResult.success(visitRecordService.recordList(request));
    }

    @ApiOperation("拜访记录状态统计")
    @PostMapping("/countStatusStatistics")
    public ResponseResult<VisitRecordStatusStatisticsVO> countStatusStatistics(@RequestBody VisitRecordQueryRequest request) {
        return ResponseResult.success(visitRecordService.countStatusStatistics(request));
    }
}