package com.zsc.edu.gateway.modules.message.entity;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zsc.edu.gateway.common.enums.IState;
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

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

/**
 * 系统公告Domain
 *
 * @author zhuang
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_bulletin")
public class Bulletin extends BaseEntity {

    /**
     * 标题
     */
    public String title;

    /**
     * 状态
     */
    public State state = State.edit;

    /**
     * 部门ID(权限)
     */
    public Long deptId;

    /**
     * 是否置顶
     */
    public Boolean top;

    /**
     * 编辑者ID
     */
    public Long editUserId;

    /**
     * 编辑者
     */
    @TableField(exist = false)
    public String editUsername;

    /**
     * 编辑时间
     */
    public LocalDateTime editTime;

    /**
     * 审核发布者ID
     */
    public Long publishUserId;

    /**
     * 审核发布者
     */
    @TableField(exist = false)
    public String publishUsername;

    /**
     * 审核发布时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public LocalDateTime publishTime;

    /**
     * 关闭者ID
     */
    public Long closeUserId;

    /**
     * 关闭者
     */
    @TableField(exist = false)
    public String closeUsername;

    /**
     * 关闭时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public LocalDateTime closeTime;

    /**
     * 内容
     */
    public String content;

    /**
     * 已读状态
     */
    @TableField(exist = false)
    public Boolean isRead;

    /**
     * 附件列表
     */
    @TableField(exist = false)
    public List<Attachment> attachments;

    public enum State implements IEnum<Integer>, IState<State> {
        edit(1,"编辑中"),
        publish(2,"已发布"),
        close(3,"已关闭");

        private final Integer value;
        private final String name;

        State(int value, String name) {
            this.value=value;
            this.name = name;
        }
        @Override
        public Integer getValue() {
            return this.value;
        }
        @Override
        public String toString() {
            return this.name;
        }
    }
}
