package cn.reghao.tnb.content.app.vod.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.content.app.vod.model.dto.CategoryAdd;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

/**
 * @author reghao
 * @date 2021-11-23 18:24:30
 */
@NoArgsConstructor
@Setter
@Getter
public class PostCategory extends BaseObject<Integer> {
    @NotNull
    private Integer pid;
    @NotBlank
    @Size(min = 1, max = 10, message = "分区名字不能超过 10 个字符")
    private String name;
    @NotNull
    private Integer sort;
    @NotNull
    private Boolean vip;

    public PostCategory(int pid, String name) {
        this.pid = pid;
        this.name = name;
        this.sort = 1;
        this.vip = false;
    }

    public PostCategory(CategoryAdd categoryAdd) {
        this.pid = categoryAdd.getPid();
        this.name = categoryAdd.getName();
        this.sort = 1;
        this.vip = categoryAdd.getVip();
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = result * 31 + name.hashCode();
        return result;
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }

        if (other instanceof PostCategory) {
            PostCategory o = (PostCategory) other;
            return o.name.equals(name);
        } else {
            return false;
        }
    }
}
