package com.starry.admin.modules.clerk.module.vo;

import com.starry.admin.modules.clerk.module.enums.ClerkDataType;
import com.starry.common.enums.ClerkReviewState;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Data;

/**
 * 店员资料审核对象 play_clerk_data_review_info
 *
 * @author admin
 * @since 2024-05-19
 */
@Data
@ApiModel(value = "店员资料内容审核返回数据", description = "店员资料内容审核信息的返回数据")
public class PlayClerkDataReviewReturnVo {

    /**
     * UUID
     */
    @ApiModelProperty(value = "审核记录ID", example = "1")
    private String id;

    /**
     * 店员ID
     */
    @ApiModelProperty(value = "店员ID", example = "1")
    private String clerkId;

    /**
     * 店员昵称
     */
    @ApiModelProperty(value = "店员昵称", example = "小明")
    private String clerkNickname;

    /**
     * 店员头像
     */
    @ApiModelProperty(value = "店员头像", example = "https://example.com/avatar.jpg")
    private String clerkAvatar;

    /**
     * 资料类型[0:昵称;1:头像;2:相册;3:录音;4:性别]
     */
    @ApiModelProperty(value = "资料类型", example = "1", notes = "0:昵称;1:头像;2:相册;3:录音;4:性别")
    private String dataType;

    /**
     * 资料类型枚举（新增字段，用于类型安全）
     */
    @ApiModelProperty(value = "资料类型枚举", example = "AVATAR", notes = "NICKNAME:昵称, AVATAR:头像, PHOTO_ALBUM:相册, RECORDING:录音, GENDER:性别")
    private ClerkDataType dataTypeEnum;

    /**
     * 资料内容
     */
    @ApiModelProperty(value = "资料内容", example = "[\"https://example.com/photo1.jpg\"]", notes = "资料内容，根据资料类型有不同格式")
    private List<String> dataContent;

    /**
     * 媒资对应的视频地址（仅当资料类型为头像/相册且为视频时有值，顺序与 dataContent 一一对应）
     */
    @ApiModelProperty(
            value = "媒资视频地址列表",
            example = "[\"https://example.com/video1.mp4\"]",
            notes = "仅当资料类型为头像/相册且为视频时有值，顺序与 dataContent 一一对应")
    private List<String> mediaVideoUrls;

    /**
     * 审核状态（0：未审核:1：审核通过，2：审核不通过）
     */
    @ApiModelProperty(value = "审核状态", example = "0", notes = "0：未审核:1：审核通过，2：审核不通过")
    private String reviewState;

    /**
     * 审核状态枚举
     */
    @ApiModelProperty(value = "审核状态枚举", example = "APPROVED", notes = "PENDING:未审核, APPROVED:审核通过, REJECTED:审核不通过")
    private ClerkReviewState reviewStateEnum;

    /**
     * 资料添加时间
     */
    @ApiModelProperty(value = "添加时间", example = "2024-01-01 12:00:00")
    private LocalDateTime addTime;

    /**
     * 审核时间
     */
    @ApiModelProperty(value = "审核时间", example = "2024-01-02 12:00:00")
    private LocalDateTime reviewTime;

    /**
     * 审核人
     */
    @ApiModelProperty(value = "审核人", example = "admin")
    private String reviewBy;

    /**
     * 审核内容
     */
    @ApiModelProperty(value = "审核内容", example = "资料完整，通过审核")
    private String reviewCon;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注", example = "资料清晰可见")
    private String remark;

    // 自定义setter方法保持两个字段的同步
    public void setDataType(String dataType) {
        this.dataType = dataType;
        try {
            this.dataTypeEnum = ClerkDataType.fromCode(dataType);
        } catch (Exception e) {
            this.dataTypeEnum = null;
        }
    }

    public void setDataTypeEnum(ClerkDataType dataTypeEnum) {
        this.dataTypeEnum = dataTypeEnum;
        this.dataType = dataTypeEnum != null ? dataTypeEnum.getCode() : null;
    }

    public ClerkDataType getDataTypeEnum() {
        // 如果枚举字段为null但字符串字段有值，尝试从字符串转换
        if (dataTypeEnum == null && dataType != null) {
            try {
                dataTypeEnum = ClerkDataType.fromCode(dataType);
            } catch (Exception e) {
                // 转换失败时保持null
            }
        }
        return dataTypeEnum;
    }

    public void setReviewState(String reviewState) {
        this.reviewState = reviewState;
        try {
            this.reviewStateEnum = ClerkReviewState.fromCode(reviewState);
        } catch (Exception e) {
            this.reviewStateEnum = null;
        }
    }

    public void setReviewStateEnum(ClerkReviewState reviewStateEnum) {
        this.reviewStateEnum = reviewStateEnum;
        this.reviewState = reviewStateEnum != null ? reviewStateEnum.getCode() : null;
    }

    public ClerkReviewState getReviewStateEnum() {
        if (reviewStateEnum == null && reviewState != null) {
            try {
                reviewStateEnum = ClerkReviewState.fromCode(reviewState);
            } catch (Exception e) {
                // ignore invalid code
            }
        }
        return reviewStateEnum;
    }

}
