package com.propertyManagement.web.controller.business.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.propertyManagement.business.domain.bo.WxProtocolBo;
import com.propertyManagement.business.domain.vo.WxProtocolVo;
import com.propertyManagement.business.service.IWxProtocolService;
import com.propertyManagement.common.annotation.Anonymous;
import com.propertyManagement.common.annotation.Log;
import com.propertyManagement.common.annotation.RepeatSubmit;
import com.propertyManagement.common.core.controller.BaseController;
import com.propertyManagement.common.core.domain.PageQuery;
import com.propertyManagement.common.core.domain.R;
import com.propertyManagement.common.core.page.TableDataInfo;
import com.propertyManagement.common.core.validate.AddGroup;
import com.propertyManagement.common.core.validate.EditGroup;
import com.propertyManagement.common.enums.BusinessType;
import com.propertyManagement.common.enums.IsEnableType;
import com.propertyManagement.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 用户协议
 *
 * @author liushuai
 * @date 2025-05-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/protocol")
public class ApiWxProtocolController extends BaseController {

    private final IWxProtocolService iWxProtocolService;

    /**
     * 获取用户协议详细信息
     *
     * @param type 主键
     */
    @Anonymous
    @GetMapping("/{type}")
    public R<WxProtocolVo> getInfo(@NotNull(message = "类型不能为空")
                                     @PathVariable Integer type) {
        WxProtocolBo protocolBo = new WxProtocolBo();
        protocolBo.setType(type);
        protocolBo.setIsEnable(IsEnableType.YES.getCode());
        List<WxProtocolVo> protocolVoList = iWxProtocolService.queryList(protocolBo);
        if (protocolVoList.isEmpty()) {
            return R.ok();
        }
        return R.ok(protocolVoList.get(0));
    }

}
