package com.hotent.auth.server.service;

import com.hotent.base.jwt.JwtAuthenticationRequest;
import com.hotent.base.jwt.JwtAuthenticationResponse;
import com.hotent.base.jwt.JwtCustomAuthenticationRequest;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.QueryFilter;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;

/**
 * 用户认证 服务类
 *
 * @author liangjc
 * @company 广州宏天软件股份有限公司
 * @email liangjc@jee-soft.cn
 * @date 2023-09-18 17:29
 */
public interface AuthenticationService {


    /**
     * 登录系统
     *
     * @param authenticationRequest
     * @return
     */
    ResponseEntity<JwtAuthenticationResponse> createAuthenticationToken(JwtAuthenticationRequest authenticationRequest) throws Exception;

    ResponseEntity<?> createCustomToken(JwtCustomAuthenticationRequest authenticationRequest);


    /**
     * 登录系统
     *
     * @param shortCode
     * @return
     */
    ResponseEntity<?> exchangeAuthenticationTokenCode(String shortCode);

    /**
     * 登录系统-单点登录
     * @param ticket
     * @param code
     * @param ssoMode
     * @param service
     * @return
     * @throws AuthenticationException
     * @throws IOException
     */
    ResponseEntity<?> ssoAuth(Optional<String> ticket, Optional<String> code, Optional<String> ssoMode, String service) throws AuthenticationException, IOException;

    /**
     * 企业微信应用进入手机端-单点登录
     * @param code
     * @return
     * @throws AuthenticationException
     */
    ResponseEntity<?> ssoWeixin(Optional<String> code) throws AuthenticationException;

    /**
     * 微信公众号进入手机端
     * @param code
     * @return
     * @throws AuthenticationException
     */
    ResponseEntity<?> weixinPublic(Optional<String> code) throws AuthenticationException;

    /**
     * 钉钉进入手机端
     * @param code
     * @return
     * @throws AuthenticationException
     */
    ResponseEntity<?> dingTalk(Optional<String> code) throws AuthenticationException;

    /**
     * 小程序登陆凭证校验
     * @param code
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> miniprogram(Optional<String> code) throws AuthenticationException;

    /**
     * 企微钉钉App扫码登录PC端
     * @param code
     * @param type
     * @return
     */
    CommonResult<?> dingtalkScan(Optional<String> code, Optional<String> type);

    /**
     * 单点登录配置
     * @return
     */
    Map<String, Object> isUseCas();

    /**
     * 刷新token
     * @param request
     * @return
     */
    ResponseEntity<?> refreshAndGetAuthenticationToken(HttpServletRequest request);

    /**
     * 退出登录
     * @param request
     */
    void signout(HttpServletRequest request);

    /**
     * 生成扫码登录二维码
     * @param type
     * @return
     * @throws AuthenticationException
     */
    ResponseEntity<?> productLoginQrCode(String type) throws AuthenticationException;


   /**钉钉扫码跳转地址
    * @description
    * @author  yangzibin
    * @date    2023/12/26 10:55
    * @param	code
    * @param	authCode
    * @param	state
    * @return  org.springframework.http.ResponseEntity<?>
    */
   CommonResult<?>  dingAuthByCode(String code,
                                     String authCode,
                                     String state) throws AuthenticationException;

    /**钉钉扫码跳转地址
     * @description
     * @author  yangzibin
     * @date    2023/12/26 10:55
     * @param	code
     * @param	authCode
     * @param	state
     * @return  org.springframework.http.ResponseEntity<?>
     */
    String  dingAuthByCodeReHtml(String code,
                                    String authCode,
                                    String state) throws AuthenticationException;

   /**扫码结果查询
    * @description
    * @author  yangzibin
    * @date    2023/12/26 15:09
    * @param	busId
    * @return  com.hotent.base.model.CommonResult<?>
    */
   CommonResult<?>  queryScanLoginInfoById(String busId)throws AuthenticationException;

    /***
     * 扫码登录
     * @param busId
     * @return
     * @throws AuthenticationException
     */
   CommonResult<?>  scanLoginCode(String clientId, String busId)throws AuthenticationException;

    /**
     * 发送登录手机验证码
     * @param mobile
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> sendMsgYzmCode(String mobile,String use,String randImageId,String  randImageCode) throws AuthenticationException;

    /**
     * 验证码登录
     * @param mobile
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> msgYzmLogin(String mobile,String code,String use) throws AuthenticationException;

    /**
     * 验证码登录
     * @param mobile
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> msgYzmLoginCode(String clientId,String mobile,String code,String use) throws AuthenticationException;

    /**
     * 忘记密码_重新设置密码功能
     * @param account 账号
     * @param mobile 手机号
     * @param validateCode 短信验证码
     * @param newPsw 新密码
     * @param reNewPsw 重复新密码
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> forgotPwd(String account, String mobile, String validateCode,
                              String newPsw, String reNewPsw) throws AuthenticationException, IOException;

    /**
     * 移除登录手机验证码
     * @param mobile
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> removeMsgYzmCode(String mobile,String use) throws AuthenticationException;

    /**
     *  刷新token
     * @param request
     * @return
     */
    ResponseEntity<?> refreshCustomAuthenticationToken(HttpServletRequest request);

    /**钉钉扫码跳转地址
     * @description
     * @author  yangzibin
     * @date    2023/12/26 10:55
     * @param	code
     * @param	authCode
     * @param	state
     * @return  org.springframework.http.ResponseEntity<?>
     */
    CommonResult<?>  getDingUserByCode(String code,
                                    String corpId,
                                    String appId) throws AuthenticationException;
    /**
     * 指纹登录验证
     * @param mobile
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> fingerPrintLogin(String type,String loginValue,String deviceId) throws AuthenticationException;

    /**
     * 获取未登录展示的应用
     * @param
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> getAppByNoAuth() throws AuthenticationException;

    /**
     * 获取未登录展示的常用应用
     * @param
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> loadMySysAppOftenByNoAuth() throws AuthenticationException;

    /**
     * 获取未登录展示的常用流程
     * @param
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> getMyOftenFlowByNoAuth() throws AuthenticationException;

    /**
     * 获取未登录的系统消息
     * @param
     * @return
     * @throws AuthenticationException
     */
    CommonResult<?> messagelistNoUser(@ApiParam(name="queryFilter",value="通用查询对象")@RequestBody QueryFilter queryFilter) throws AuthenticationException;

    /**
     * @description  获取移动端欢迎页数据
     * @author  yangzibin
     * @date    2024/9/13 16:39
     * @param	orgId
     * @return  com.hotent.base.model.CommonResult<?>
     */
    CommonResult<?> getWelcomeDage(String orgId) throws AuthenticationException;
}
