import { Column, Entity, Index, PrimaryColumn } from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";
import { UserGroup } from "./user-group.js";

@Entity()
@Index(["name", "userId"], { unique: true })
@Index(["name", "userGroupId"], { unique: true })
export class UserEmoji {
	@PrimaryColumn(id())
	public id: string;

	@Column("timestamp with time zone")
	public createdAt: Date;

	@Index()
	@Column("varchar", {
		length: 128,
	})
	public name: string;

	@Index()
	@Column({
		...id(),
		nullable: true,
	})
	public userId: User["id"] | null;

	@Index()
	@Column({
		...id(),
		nullable: true,
	})
	public userGroupId: UserGroup["id"] | null;

	@Column("varchar", {
		length: 512,
	})
	public originalUrl: string;

	@Column("varchar", {
		length: 512,
		default: "",
	})
	public publicUrl: string;

	@Column("varchar", {
		length: 64,
		nullable: true,
	})
	public type: string | null;

	@Column("boolean", {
		default: false,
	})
	public glyph: boolean;

	@Column("integer", {
		nullable: true,
		comment: "Image width",
	})
	public width: number | null;

	@Column("integer", {
		nullable: true,
		comment: "Image height",
	})
	public height: number | null;
}
