package com.cool.store.controller.webc;

import com.cool.store.enums.close.CloseTypeEnum;
import com.cool.store.request.close.store.CloseStoreApplyRequest;
import com.cool.store.request.close.store.CloseStoreCancelRequest;
import com.cool.store.request.close.store.MiniCloseStoreQueryRequest;
import com.cool.store.request.close.store.ReCloseStoreApplyRequest;
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.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

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

    @ApiOperation("申请闭店")
    @PostMapping("/apply")
    public ResponseResult<Boolean> applyCloseStore(@RequestBody @Valid CloseStoreApplyRequest request) {
        request.setCloseType(CloseTypeEnum.INITIATE.getCloseType());
        return ResponseResult.success(closeStoreService.applyCloseStore(request));
    }

    @ApiOperation("拒绝后重新提交申请闭店")
    @PostMapping("/reapply")
    public ResponseResult<Boolean> reApplyCloseStore(@RequestBody @Valid ReCloseStoreApplyRequest request) {
        return ResponseResult.success(closeStoreService.reApplyCloseStore(request));
    }

    @ApiOperation("闭店申请列表")
    @GetMapping("/page")
    public ResponseResult<PageInfo<MiniCloseStoreSimpleVO>> closeStorePage(MiniCloseStoreQueryRequest request) {
        return ResponseResult.success(closeStoreService.getMiniCloseStoreSimpleInfoList(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("闭店原因列表")
    @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("取消闭店申请")
    @PostMapping("/cancel")
    public ResponseResult<Boolean> cancelCloseStore(@RequestBody @Valid CloseStoreCancelRequest request) {
        return ResponseResult.success(closeStoreService.cancelApply(request.getCloseStoreId()));
    }

    @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));
    }
}
