package com.oqpo.api.web.dto.response.token;

import com.oqpo.api.constant.ApiConstants;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Getter
@Setter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class TokenResponse {
    @ApiModelProperty(value = "사용자ID")
    private String userId;

    @ApiModelProperty(value = "시스템 관리자 여부")
    private String systemAdminYn;

    @ApiModelProperty(value = "슈퍼 관리자 여부")
    private String superAdminYn;

    @ApiModelProperty(value = "권한구분")
    private String authTpCd;

    @ApiModelProperty(value = "로그인 구별 정보")
    private Boolean isLogin;

    @ApiModelProperty(value = "가맹점아이디")
    private String afflShopId;

    @ApiModelProperty(value = "브랜드아이디")
    private String brandId;


    @ApiModelProperty(value = "로그인회사명")
    private String authTpNm;



    public static TokenResponse toDTO(Jws<Claims> claims) {
        return TokenResponse.builder()
                .userId(claims.getBody().getSubject())
                .systemAdminYn((String) claims.getBody().get(ApiConstants.CLAIMS_SUPER_ADMIN_YN))
                .superAdminYn((String) claims.getBody().get(ApiConstants.CLAIMS_SUPER_ADMIN_YN))
                .authTpCd((String) claims.getBody().get(ApiConstants.CLAIMS_AUTH_TP_CD))
                .isLogin((Boolean)claims.getBody().get(ApiConstants.CLAIMS_IS_LOGIN))
                .afflShopId((String) claims.getBody().get(ApiConstants.CLAIMS_AFFL_SHOP_ID))
                .brandId((String) claims.getBody().get(ApiConstants.CLAIMS_BRAND_ID))
                .authTpNm((String) claims.getBody().get(ApiConstants.CLAIMS_AUTH_TP_NM))
                .build();
    }
}
