package com.chinaweal.aiccs.org.entity.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * OAuth用户信息响应DTO
 *
 * @author lroyia
 * @since 2025/11/21
 */
@Data
@ApiModel(description = "OAuth用户信息响应DTO")
public class UserinfoResponseDTO {

    @ApiModelProperty(value = "用户ID", example = "user123456")
    private String sub;

    @ApiModelProperty(value = "用户名", example = "john.doe")
    @JsonProperty("preferred_username")
    private String preferredUsername;

    @ApiModelProperty(value = "真实姓名", example = "张三")
    private String name;

    @ApiModelProperty(value = "邮箱", example = "zhangsan@example.com")
    private String email;

    @ApiModelProperty(value = "邮箱是否已验证", example = "true")
    @JsonProperty("email_verified")
    private Boolean emailVerified;

    @ApiModelProperty(value = "手机号", example = "13800138000")
    @JsonProperty("phone_number")
    private String phoneNumber;

    @ApiModelProperty(value = "手机号是否已验证", example = "true")
    @JsonProperty("phone_number_verified")
    private Boolean phoneNumberVerified;

    @ApiModelProperty(value = "头像URL", example = "https://example.com/avatar.jpg")
    private String picture;

    @ApiModelProperty(value = "个人资料URL", example = "https://example.com/profile")
    private String profile;

    @ApiModelProperty(value = "网站URL", example = "https://example.com")
    private String website;

    @ApiModelProperty(value = "性别", example = "male")
    private String gender;

    @ApiModelProperty(value = "生日", example = "1990-01-01")
    private String birthdate;

    @ApiModelProperty(value = "时区", example = "Asia/Shanghai")
    private String zoneinfo;

    @ApiModelProperty(value = "地区", example = "zh-CN")
    private String locale;

    @ApiModelProperty(value = "更新时间", example = "2025-11-21T10:30:00")
    @JsonProperty("updated_at")
    private LocalDateTime updatedAt;

    @ApiModelProperty(value = "用户角色列表")
    private List<String> roles;

    @ApiModelProperty(value = "用户权限列表")
    private List<String> permissions;

    @ApiModelProperty(value = "用户组")
    private String groups;

    @ApiModelProperty(value = "部门ID", example = "dept001")
    @JsonProperty("department_id")
    private String departmentId;

    @ApiModelProperty(value = "部门名称", example = "技术部")
    @JsonProperty("department_name")
    private String departmentName;

    @ApiModelProperty(value = "职位", example = "软件工程师")
    private String position;

    @ApiModelProperty(value = "员工编号", example = "EMP001")
    @JsonProperty("employee_number")
    private String employeeNumber;

    @ApiModelProperty(value = "是否启用", example = "true")
    private Boolean enabled;

    @ApiModelProperty(value = "账户未过期", example = "true")
    @JsonProperty("account_non_expired")
    private Boolean accountNonExpired;

    @ApiModelProperty(value = "账户未锁定", example = "true")
    @JsonProperty("account_non_locked")
    private Boolean accountNonLocked;

    @ApiModelProperty(value = "凭据未过期", example = "true")
    @JsonProperty("credentials_non_expired")
    private Boolean credentialsNonExpired;

    /**
     * 构造简化版本的用户信息（根据授权范围）
     */
    public static UserinfoResponseDTO createBasicUserInfo(String userId, String username, String name) {
        UserinfoResponseDTO userinfo = new UserinfoResponseDTO();
        userinfo.setSub(userId);
        userinfo.setPreferredUsername(username);
        userinfo.setName(name);
        return userinfo;
    }

    /**
     * 构造完整版本的用户信息
     */
    public static UserinfoResponseDTO createFullUserInfo(String userId, String username, String name,
                                                         String email, String phoneNumber,
                                                         List<String> roles, List<String> permissions) {
        UserinfoResponseDTO userinfo = createBasicUserInfo(userId, username, name);
        userinfo.setEmail(email);
        userinfo.setEmailVerified(true);
        userinfo.setPhoneNumber(phoneNumber);
        userinfo.setPhoneNumberVerified(true);
        userinfo.setRoles(roles);
        userinfo.setPermissions(permissions);
        userinfo.setEnabled(true);
        userinfo.setAccountNonExpired(true);
        userinfo.setAccountNonLocked(true);
        userinfo.setCredentialsNonExpired(true);
        userinfo.setUpdatedAt(LocalDateTime.now());
        userinfo.setGroups("可写用户");
        return userinfo;
    }
}