package com.dora.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

/**
 * 认证相关DTO
 */
public class AuthDto {
    
    private AuthDto() {
        // Private constructor to prevent instantiation
    }

    @Data
    @Schema(description = "短信验证码登录请求")
    public static class SmsLoginRequest {
        @NotBlank(message = "手机号不能为空")
        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @NotBlank(message = "验证码不能为空")
        @Size(min = 6, max = 6, message = "验证码必须是6位数字")
        @Schema(description = "短信验证码", example = "123456")
        private String code;
    }

    @Data
    @Schema(description = "密码登录请求")
    public static class PasswordLoginRequest {
        @NotBlank(message = "手机号不能为空")
        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @NotBlank(message = "密码不能为空")
        @Schema(description = "登录密码", example = "123456")
        private String password;
    }

    @Data
    @Schema(description = "用户注册请求")
    public static class RegisterRequest {
        @NotBlank(message = "手机号不能为空")
        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @NotBlank(message = "验证码不能为空")
        @Size(min = 6, max = 6, message = "验证码必须是6位数字")
        @Schema(description = "短信验证码", example = "123456")
        private String code;

        @Schema(description = "登录密码（可选）", example = "123456", nullable = true)
        private String password;

        @Schema(description = "邀请码（可选）", example = "ABC123")
        private String inviteCode;
    }

    @Data
    @Schema(description = "用户信息响应")
    public static class UserInfoResponse {
        @Schema(description = "用户ID", example = "17543607206742139")
        private String id;

        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @Schema(description = "用户名", example = "用户123456")
        private String username;

        @Schema(description = "真实用户名", example = "张三")
        private String realUsername;

        @Schema(description = "身份证号码", example = "110101199001011234")
        private String idNumber;

        @Schema(description = "角色（0游客/1普通/2VIP/3SVIP）", example = "1")
        private Integer role;

        @Schema(description = "会员到期时间", example = "2024-12-31T23:59:59")
        private String membershipExpiresAt;

        @Schema(description = "头像URL", example = "https://img.remit.ee/api/file/BQACAgUAAyEGAASHRsPbAAJblmiMe_d10FU66N4nQAQMfscumNdFAALDGwACUsZhVEphmi-3nWulNgQ.png")
        private String avatarUrl;

        @Schema(description = "是否实名认证", example = "0")
        private Integer isVerified;

        @Schema(description = "推广码", example = "ABC123")
        private String inviteCode;

        @Schema(description = "推广等级", example = "1")
        private Integer promotionLevel;

        @Schema(description = "积分余额", example = "1000")
        private Integer points;

        @Schema(description = "积分过期时间", example = "2024-12-31T23:59:59")
        private String pointsExpiresAt;

        @Schema(description = "最新积分套餐名称", example = "基础套餐")
        private String latestPointsPackageName;

        @Schema(description = "注册时间", example = "2024-01-01T00:00:00")
        private String createTime;

        @Schema(description = "是否已绑定微信", example = "true")
        private Boolean wechatBound;

        @Schema(description = "会员类型", example = "付费会员", allowableValues = {"非会员", "付费会员", "纯兑换会员", "兑换后付费会员", "赠送会员", "过期会员"})
        private String membershipType;

        @Schema(description = "是否为不参与收益分成的会员（兑换会员或赠送会员）", example = "false")
        private Boolean isExchangeMemberOnly;

        @Schema(description = "会员是否已过期", example = "false")
        private Boolean isMembershipExpired;
    }

    @Data
    @Schema(description = "登录响应")
    public static class LoginResponse {
        @Schema(description = "JWT令牌", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
        private String token;

        @Schema(description = "令牌过期时间", example = "2024-12-31T23:59:59")
        private String tokenExpiresAt;

        @Schema(description = "用户信息")
        private UserInfoResponse userInfo;
    }

    @Data
    @Schema(description = "刷新Token响应")
    public static class RefreshTokenResponse {
        @Schema(description = "是否成功")
        private boolean success;

        @Schema(description = "是否刷新了token（false表示token无需刷新）")
        private boolean refreshed;

        @Schema(description = "新的或原始的JWT令牌", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
        private String token;

        @Schema(description = "令牌过期时间", example = "2024-12-31T23:59:59")
        private String tokenExpiresAt;

        @Schema(description = "响应消息")
        private String message;
    }

    @Data
    @Schema(description = "修改用户信息请求")
    public static class UpdateProfileRequest {
        @NotBlank(message = "用户名不能为空")
        @Size(min = 2, max = 20, message = "用户名长度必须在2-20位之间")
        @Pattern(regexp = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]+$", message = "用户名只能包含字母、数字、下划线和中文")
        @Schema(description = "用户昵称", example = "新昵称")
        private String username;

        @Schema(description = "头像URL", example = "https://example.com/avatar.jpg")
        private String avatarUrl;
    }

    @Data
    @Schema(description = "修改用户名请求")
    public static class UpdateUsernameRequest {
        @NotBlank(message = "新用户名不能为空")
        @Size(min = 2, max = 20, message = "用户名长度必须在2-20位之间")
        @Pattern(regexp = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]+$", message = "用户名只能包含字母、数字、下划线和中文")
        @Schema(description = "新用户名", example = "newuser123")
        private String newUsername;
    }

    @Data
    @Schema(description = "忘记密码重置请求")
    public static class ResetPasswordRequest {
        @NotBlank(message = "手机号不能为空")
        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @NotBlank(message = "验证码不能为空")
        @Size(min = 6, max = 6, message = "验证码必须是6位数字")
        @Schema(description = "短信验证码", example = "123456")
        private String code;

        @NotBlank(message = "新密码不能为空")
        @Size(min = 6, max = 20, message = "密码长度必须在6-20位之间")
        @Schema(description = "新密码")
        private String newPassword;
    }

    @Data
    @Schema(description = "实名认证初始化响应")
    public static class VerificationInitResponse {
        @Schema(description = "认证ID", example = "certify_123456")
        private String certifyId;

        @Schema(description = "认证URL", example = "https://certify.aliyun.com/...")
        private String certifyUrl;
    }

    @Data
    @Schema(description = "实名认证状态响应")
    public static class VerificationStatusResponse {
        @Schema(description = "认证状态", example = "PASS")
        private String status;

        @Schema(description = "认证结果描述", example = "认证通过")
        private String message;
    }

    @Data
    @Schema(description = "修改真实身份信息请求")
    public static class UpdateRealIdentityRequest {
        @NotBlank(message = "真实用户名不能为空")
        @Size(min = 2, max = 32, message = "真实用户名长度必须在2-32位之间")
        @Schema(description = "真实用户名", example = "张三")
        private String realUsername;

        @NotBlank(message = "身份证号码不能为空")
        @Pattern(regexp = "^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$", 
                message = "身份证号码格式不正确")
        @Schema(description = "身份证号码", example = "110101199001011234")
        private String idNumber;
    }

    @Data
    @Schema(description = "真实身份信息响应")
    public static class RealIdentityResponse {
        @Schema(description = "真实用户名", example = "张三")
        private String realUsername;

        @Schema(description = "身份证号码", example = "110101199001011234")
        private String idNumber;

        @Schema(description = "是否实名认证", example = "1")
        private Integer isVerified;
    }

    @Data
    @Schema(description = "更新手机号请求")
    public static class UpdatePhoneRequest {
        @NotBlank(message = "新手机号不能为空")
        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
        @Schema(description = "新手机号", example = "13800138000")
        private String newPhone;

        @NotBlank(message = "验证码不能为空")
        @Size(min = 6, max = 6, message = "验证码必须是6位数字")
        @Schema(description = "短信验证码", example = "123456")
        private String code;
    }

    @Data
    @Schema(description = "修改密码请求")
    public static class UpdatePasswordRequest {
        @NotBlank(message = "手机号不能为空")
        @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @NotBlank(message = "验证码不能为空")
        @Size(min = 6, max = 6, message = "验证码必须是6位数字")
        @Schema(description = "短信验证码", example = "123456")
        private String code;

        @NotBlank(message = "新密码不能为空")
        @Size(min = 6, max = 20, message = "密码长度必须在6-20位之间")
        @Schema(description = "新密码", example = "newpassword123")
        private String newPassword;
    }

    @Data
    @Schema(description = "验证当前密码请求")
    public static class VerifyPasswordRequest {
        @NotBlank(message = "当前密码不能为空")
        @Schema(description = "当前密码", example = "currentpassword123")
        private String password;
    }
} 