package com.sonic.frog.client;

import com.alibaba.fastjson.annotation.JSONField;
import com.sonic.common.auth.domains.AppClientEnum;
import com.sonic.frog.domain.bo.ThirdAuthBo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

public interface AppleIdLoginValidateOauth2Client {

    /**
     * 验证token是否有效
     * @param accessToken
     * @param appClient
     * @return
     */
    boolean isValid(String accessToken, AppClientEnum appClient);

    /**
     * 解析token数据
     * @param idToken
     * @return
     */
    ThirdAuthBo parseIdByIdToken(String idToken);


    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    class CusJws {
        private JwsHeader jwsHeader;
        private JwsPayload jwsPayload;
        private String signature;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    class JwsHeader {
        private String kid;
        private String alg;
    }


    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    class JwsPayload {
        public final static String ISS = "https://appleid.apple.com";

        private String iss;
        private String sub;
        private String aud;
        private Long exp;
        private Long iat;
        private String nonce;
        private String email;
        @JSONField(name = "email_verified")
        private Boolean emailVerified;
    }
}
