package com.cool.store.controller.webc;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.context.PartnerUserHolder;
import com.cool.store.dto.pre.fry.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PreFryQualificationApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2025/6/21 18:11
 * @Version 1.0
 */
@Slf4j
@Api(tags = "预炸-申请-小程序")
@RestController
@RequestMapping("/mini/pre/apply/")
public class MiniPreFryQualificationApplyController {


    @Resource
    PreFryQualificationApplyService preFryQualificationApplyService;


    @ApiOperation("预炸资质申请提交")
    @PostMapping("/submitApply")
    public ResponseResult<Long> submitApply(@RequestBody @Validated ApplyDTO dto) {
        log.info("预炸资质申请提交：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFryQualificationApplyService.submitApply( dto, PartnerUserHolder.getUser()));
    }

    @ApiOperation("预炸资质申请重新提交")
    @PostMapping("/reSubmitApply")
    public ResponseResult<Long> reSubmitApply(@RequestBody @Validated ApplyDTO dto) {
        log.info("预炸资质申请重新提交：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFryQualificationApplyService.reSubmitApply( dto, PartnerUserHolder.getUser()));
    }


    @ApiOperation("预炸资质申请详情")
    @GetMapping("/getApplyDetail")
    public ResponseResult<ApplyDetailDTO> getApplyDetail(@RequestParam(required = true, value = "id") Long id) {
        log.info("预炸资质申请详情：{}", JSONObject.toJSONString(id));
        return ResponseResult.success(preFryQualificationApplyService.getApplyDetail(id));
    }


    @ApiOperation("根据门店编码和类型查询申请详情")
    @GetMapping("/getByStoreCodeAndApplyType")
    public ResponseResult<ApplyDTO> getByStoreCodeAndApplyType(@RequestParam(required = true, value = "storeCode") String storeCode,
                                                         @RequestParam(required = true, value = "applyType") Integer applyType) {
        return ResponseResult.success(preFryQualificationApplyService.getByStoreCodeAndApplyType(storeCode,applyType));
    }

    @ApiOperation("根据申请ID获取审批记录列表")
    @GetMapping("/getApprovalRecordById")
    public ResponseResult<List<ApprovalRecordDTO>> getApprovalRecordById(@RequestParam(required = true, value = "id") Long id) {
        log.info("根据申请ID获取审批记录列表：{}", JSONObject.toJSONString(id));
        return ResponseResult.success(preFryQualificationApplyService.getApprovalRecordById(id));
    }


    @ApiOperation("获取门店最高优先级申请类型")
    @GetMapping("/getMinApplyType")
    public ResponseResult<Integer> getMinApplyType(@RequestParam(required = true, value = "storeCode") String storeCode) {
        return ResponseResult.success(preFryQualificationApplyService.getMinApplyType(storeCode));
    }

    @ApiOperation("根据门店编码获取申请类型审批状态")
    @GetMapping("/getListByStoreCode")
    public ResponseResult<List<PreFryQualificationApplyDTO>> getListByStoreCode(@RequestParam(required = true, value = "storeCode") String storeCode) {
        return ResponseResult.success(preFryQualificationApplyService.getListByStoreCode(storeCode));
    }

}
