package com.cool.store.controller.webb;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.dto.pre.fry.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PreFryQualificationApplyService;
import com.github.pagehelper.PageInfo;
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:03
 * @Version 1.0
 */
@Slf4j
@Api(tags = "预炸-申请")
@RestController
@RequestMapping("/pc/pre/apply/")
public class PreFryQualificationApplyController {

    @Resource
    PreFryQualificationApplyService preFryQualificationApplyService;


    @ApiOperation("预炸资质申请管理列表")
    @PostMapping("/queryApplyManagementList")
    public ResponseResult<PageInfo<ApplyManagementDTO>> queryApplyManagementList(@RequestBody @Validated ApplyManagementQueryDTO dto) {
        log.info("预炸资质申请管理列表：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFryQualificationApplyService.queryApplyManagementList( dto));
    }

    @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("/getApplyDetail")
    public ResponseResult<ApplyDetailDTO> getApplyDetail(@RequestParam(required = true, value = "id") Long id) {
        log.info("查询预炸品：{}", JSONObject.toJSONString(id));
        return ResponseResult.success(preFryQualificationApplyService.getApplyDetail(id));
    }

    @ApiOperation("申请审批  取消资格")
    @PostMapping("/audit")
    public ResponseResult<Boolean> audit(@RequestBody @Validated ApplyAuditDTO dto) {
        log.info("预炸资质申请管理列表：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFryQualificationApplyService.audit(dto,CurrentUserHolder.getUser()));
    }

}
