package com.cool.store.controller.webb;

import com.cool.store.request.close.store.CloseStoreQueryRequest;
import com.cool.store.request.close.store.CloseStoreAuditRequest;
import com.cool.store.response.AuditInfoResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.close.CloseStoreService;
import com.cool.store.vo.close.store.*;
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;
import java.util.List;

/**
 * <p>
 * 闭店审批 前端控制器
 * </p>
 *
 * @author wangff
 * @since 2025/10/9
 */
@Api(tags = "闭店管理")
@RestController
@RequestMapping("/pc/close/store")
@RequiredArgsConstructor
@Validated
public class CloseStoreController {
    private final CloseStoreService closeStoreService;

    @ApiOperation("闭店审批待办")
    @GetMapping("/todoPage")
    public ResponseResult<PageInfo<CloseStoreInfoListVO>> getAuditTodoList(CloseStoreQueryRequest request) {
        return ResponseResult.success(closeStoreService.closeStoreAuditList(request));
    }

    @ApiOperation("闭店管理列表")
    @GetMapping("/recordPage")
    public ResponseResult<PageInfo<CloseStoreInfoListVO>> getCloseStoreRecordList(CloseStoreQueryRequest request) {
        return ResponseResult.success(closeStoreService.closeStoreInfoList(request));
    }

    @ApiOperation("审批通过")
    @PostMapping("/audit/pass")
    public ResponseResult<Boolean> auditPass(@RequestBody CloseStoreAuditRequest request) {
        return ResponseResult.success(closeStoreService.auditPass(request));
    }

    @ApiOperation("审批拒绝")
    @PostMapping("/audit/reject")
    public ResponseResult<Boolean> auditReject(@RequestBody CloseStoreAuditRequest request) {
        return ResponseResult.success(closeStoreService.auditReject(request));
    }

    @ApiOperation("查询闭店审批记录")
    @GetMapping("/audit/list")
    @ApiImplicitParam(name = "closeStoreId", value = "闭店申请id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<List<AuditInfoResponse>> getAuditList(@NotNull(message = "闭店申请id不能为空") Long closeStoreId) {
        return ResponseResult.success(closeStoreService.getAuditRecordList(closeStoreId));
    }

    @ApiOperation("根据闭店申请id获取闭店申请详细")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "closeStoreId", value = "闭店申请id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<CloseStoreInfoDetailVO> getCloseStoreDetail(@NotNull(message = "闭店申请id不能为空") Long closeStoreId) {
        return ResponseResult.success(closeStoreService.getCloseStoreInfoDetail(closeStoreId, true));
    }

    @ApiOperation("根据闭店申请id获取闭店申请简单信息")
    @GetMapping("/simple")
    @ApiImplicitParam(name = "closeStoreId", value = "闭店申请id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<CloseStoreSimpleVO> getCloseStoreSimple(@NotNull(message = "闭店申请id不能为空") Long closeStoreId) {
        return ResponseResult.success(closeStoreService.getCloseStoreSimpleInfo(closeStoreId));
    }

    @ApiOperation("根据审批id获取闭店申请详细")
    @GetMapping("/detailByAudit")
    @ApiImplicitParam(name = "closeStoreAuditId", value = "审批id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<CloseStoreInfoDetailVO> getCloseStoreDetailByAuditId(@NotNull(message = "审批id不能为空") Long closeStoreAuditId) {
        return ResponseResult.success(closeStoreService.getCloseStoreInfoDetailByAuditId(closeStoreAuditId));
    }

    @ApiOperation("闭店原因列表")
    @GetMapping("/closeReasonList")
    @ApiImplicitParam(name = "closeType", value = "闭店发起方式，1主动发起，2云流水发起", required = true, dataType = "Integer", paramType = "query")
    public ResponseResult<List<StoreCloseReasonVO>> getStoreCloseReasonList(Integer closeType) {
        return ResponseResult.success(closeStoreService.getStoreCloseReasonList(closeType));
    }

    @ApiOperation("闭店状态列表")
    @GetMapping("/closeStatusList")
    public ResponseResult<List<CloseStoreStatusVO>> getCloseStoreStatusList() {
        return ResponseResult.success(closeStoreService.getCloseStoreStatusList());
    }
}
