package com.backendsys.modules.upload.entity;

import com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeAdapter;
import com.baomidou.mybatisplus.annotation.*;
import com.google.gson.annotations.JsonAdapter;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;

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

@Data
@TableName("sys_file")
public class SysFile {

    public static interface Update{}
    public static interface UpdateBatch{}
    public static interface Delete{}
    public static interface DeleteBatch{}
    public static interface SelectByMd5{}

    @TableId(type = IdType.AUTO)
    @NotNull(message = "id 不能为空", groups = { Update.class })
    private Long id;

    @TableField(exist = false)
    @NotNull(message = "ids 不能为空", groups = { UpdateBatch.class })
    @Size(min = 1, message = "ids 的数量必须大于 0", groups = { UpdateBatch.class })
    private List<Long> ids;

    @TableField(updateStrategy = FieldStrategy.NOT_NULL)
    private Long category_id;

    @TableField(exist = false)
    private String category_name;
    private String request_id;

    private String upload_id;
    private Integer upload_chunk_count;
    private Integer upload_chunk_index;

    private Long user_id;
    @TableField(exist = false)
    private String username;

    @NotEmpty(message = "文件名不能为空", groups = { Update.class })
    @Size(max = 50, message = "文件名长度不超过 {max} 字符", groups = { Update.class })
    private String name;
    private String content_type;
    private String url;
    private String url_thumb;

    @NotEmpty(message = "object_key 不能为空", groups = { Delete.class })
    private String object_key;
    @TableField(exist = false)
    @NotNull(message = "object_keys 不能为空", groups = { DeleteBatch.class })
    @Size(min = 1, message = "object_keys 的数量必须大于 0", groups = { DeleteBatch.class })
    private List<String> object_keys;

    private Long size;

    @NotEmpty(message = "md5 不能为空", groups = { SelectByMd5.class })
    private String md5;
    private Integer target;         // 上传目标 (-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云)
    @TableField(exist = false)
    private String target_label;
    @TableField(exist = false)
    private Boolean is_exist;

    // "上传时间" 只有 秒传 和 合并重复MD5 的时候会更新，"编辑" 的时候不变
    @JsonAdapter(LocalDateTimeAdapter.class)
    private LocalDateTime upload_time;

    @JsonAdapter(LocalDateTimeAdapter.class)
    private LocalDateTime create_time;
    @JsonAdapter(LocalDateTimeAdapter.class)
    private LocalDateTime update_time;
}
