package com.yd.csf.api.controller;

import com.yd.common.enums.ResultCode;
import com.yd.common.result.Result;
import com.yd.csf.api.service.ApiTaxationService;
import com.yd.csf.service.model.FnaCustomer;
import com.yd.csf.service.service.CustomerService;
import com.yd.csf.service.service.FnaCustomerService;
import com.yd.csf.service.vo.CustomerVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * fna_customer接口
 *
 * @author jianan
 * @since 2025-07-31
 */
@RestController
@RequestMapping("/fna_customer")
@Tag(name = "fna_customer接口")
public class ApiFnaCustomerController {

    @Resource
    private FnaCustomerService fnaCustomerService;

    @Resource
    private CustomerService customerService;

    @Resource
    private ApiTaxationService apiTaxationService;


    /**
     * 删除fna
     *
     * @param deleteRequest
     * @param request
     * @return
     */
//    @PostMapping("/delete")
//    public Result<Boolean> deleteFna(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
//        if (deleteRequest == null || deleteRequest.getId() <= 0) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        User user = userService.getLoginUser(request);
//        long id = deleteRequest.getId();
//        // 判断是否存在
//        Customer oldFna = customerService.getById(id);
//        ThrowUtils.throwIf(oldFna == null, ErrorCode.NOT_FOUND_ERROR);
//        // 仅本人或管理员可删除
//        if (!oldFna.getUserId().equals(user.getId()) && !userService.isAdmin(request)) {
//            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
//        }
//        // 操作数据库
//        boolean result = customerService.removeById(id);
//        ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
//        return Result.success(true);
//    }



    /**
     * 根据 fnaBizId 获取客户（封装类）
     *
     * @param fnaBizId
     * @return
     */
    @GetMapping("/get/vo")
    @Operation(summary = "根据 fnaBizId 获取客户详情")
    public Result<CustomerVO> getCustomerVOByCustomerBizId(@RequestParam("fnaBizId") String fnaBizId, HttpServletRequest request) {
        if (fnaBizId == null) {
            return Result.fail(ResultCode.PARAMS_ERROR.getCode(), "fnaBizId 不能为空");
        }
        // 查询数据库
        FnaCustomer fnaCustomer = fnaCustomerService.lambdaQuery()
                .eq(FnaCustomer::getFnaBizId, fnaBizId)
                .one();
        if (fnaCustomer == null) {
            return Result.fail(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
        }
        // 获取客户封装类
        return Result.success(fnaCustomerService.getCustomerVO(fnaCustomer));
    }

    /**
     * 分页获取客户列表（仅管理员可用）
     *
     * @param fnaQueryRequest
     * @return
     */
//    @PostMapping("/list/page")
//    public Result<Page<Customer>> listFnaByPage(@RequestBody FnaQueryRequest fnaQueryRequest) {
//        long current = fnaQueryRequest.getPageNo();
//        long size = fnaQueryRequest.getPageSize();
//        // 查询数据库
//        Page<Customer> fnaPage = customerService.page(new Page<>(current, size),
//                customerService.getQueryWrapper(fnaQueryRequest));
//        return Result.success(fnaPage);
//    }

}
