package com.gxwebsoft.common.system.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 用户角色扩展实体（支持多角色）
 *
 * @author 科技小王子
 * @since 2026-04-14
 */
@Data
@TableName("gxwebsoft_core.sys_user_role_extend")
@Schema(name = "UserRoleExtend", description = "用户角色扩展")
public class UserRoleExtend implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "ID")
    @TableId(type = IdType.AUTO)
    private Integer id;

    @Schema(description = "用户ID")
    private Integer userId;

    @Schema(description = "角色类型: admin管理员 salesman业务员 referrer推荐人")
    private String roleType;

    @Schema(description = "是否主角色 0否 1是")
    private Integer isPrimary;

    @Schema(description = "权限配置(JSON)")
    private String permissions;

    @Schema(description = "最大客资分配数(业务员)")
    private Integer maxLeads;

    @Schema(description = "佣金比例%(业务员)")
    private BigDecimal commissionRate;

    @Schema(description = "推荐奖金%(推荐人)")
    private BigDecimal referralBonus;

    @Schema(description = "状态: 0禁用 1启用")
    private Integer status;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    // ========== 关联信息（非数据库字段）==========
    @Schema(description = "用户昵称")
    private String userName;

    @Schema(description = "用户电话")
    private String userPhone;

    @Schema(description = "当前分配的客资数")
    private Integer currentLeads;

    // ========== 角色类型常量 ==========
    public static final String ROLE_ADMIN = "admin";         // 管理员
    public static final String ROLE_SALESMAN = "salesman";  // 业务员
    public static final String ROLE_REFERRER = "referrer";   // 推荐人

    public String getRoleTypeText() {
        if (this.roleType == null) return "";
        return switch (this.roleType) {
            case ROLE_ADMIN -> "管理员";
            case ROLE_SALESMAN -> "业务员";
            case ROLE_REFERRER -> "推荐人";
            default -> this.roleType;
        };
    }
}
