package jnpf.model.cultivate.dto.teaching;

import jnpf.entity.cultivate.TeachingRecord;
import jnpf.enums.cultivate.TeachingRecordTypeEnum;
import jnpf.model.cultivate.v2.teaching.model.V2Attachment;
import jnpf.util.DateDetail;
import jnpf.util.UserProvider;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RecordSaveDto {
    /**
     * 门店id
     */
    @NotBlank(message = "门店id不能为空")
    private String storeId;
    /**
     * 门店名称（要做历史备份）
     */
    @NotBlank(message = "门店名称不能为空")
    private String storeName;
    /**
     * 技能点id
     */
    @NotBlank(message = "技能点id不能为空")
    private String skillId;
    /**
     * 日期(yyyy-MM-dd)
     */
    @NotBlank(message = "日期不能为空")
    private String date;

    /** 附件列表(图片&视频) */
    @NotNull(message = "附件不能为空")
    @Size(min = 1, max = 9, message = "至少上传1个附件, 最多9个")
    private List<V2Attachment> fileList;

    /**
     * 练习视频地址[暂弃]
     */
    private String videoPath;

    /**
     * 视频类型(1-竖屏播放, 2-横屏播放)[暂弃]
     */
    private Integer videoActionType;

    /**
     * 练习时长(秒)[暂弃]
     */
    private BigDecimal videoDuration;

    /** 备注 */
    private String remark;

    public static TeachingRecord convert(RecordSaveDto saveDto) {
        return TeachingRecord.builder()
                .type(TeachingRecordTypeEnum.LX.getCode())
                .storeId(saveDto.getStoreId())
                .storeName(saveDto.getStoreName())
                .skillId(saveDto.getSkillId())
                .userId(UserProvider.getLoginUserId())
                .date(DateDetail.getStr2Date(saveDto.getDate()))
                .remark(saveDto.getRemark())
                .build();
    }
}