package com.hzs.member.self.controller.api;

import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.self.service.ICuSelfServiceLogService;
import com.hzs.member.self.vo.SelfVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自助服务控制类
 */
@Slf4j
@RequestMapping("/api/self")
@RestController
public class ApiSelfController extends BaseController {

    @Autowired
    private ICuSelfServiceLogService iCuSelfServiceLogService;

    /**
     * 自助权限查询
     */
    @GetMapping("/authority")
    public AjaxResult validateSelfAuthority() {
        Long userId = SecurityUtils.getUserId();
        Integer pkCountry = SecurityUtils.getPkCountry();
        Integer showAddress = iCuSelfServiceLogService.showHiddenAddress(userId, pkCountry);
        SelfVO selfVO = SelfVO.builder()
                .existAddress(showAddress)
                .selfRevokeOrder(showAddress)
                .existDomicile(iCuSelfServiceLogService.showIndexDomicile(pkCountry, userId))
                .existRealName(EYesNo.YES.getIntValue())
                .build();
        return AjaxResult.success(selfVO);
    }
}
