import {
	Column,
	Entity,
	Index,
	JoinColumn,
	ManyToOne,
	PrimaryColumn,
} from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";
import { Memoriet } from "./memoriet.js";

@Entity("memoriet_view")
@Index(["memorietId", "viewerId"], { unique: true })
export class MemorietView {
	@PrimaryColumn(id())
	public id: string;

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

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

	@Index()
	@Column(id())
	public memorietId: Memoriet["id"];

	@ManyToOne(() => Memoriet, { onDelete: "CASCADE" })
	@JoinColumn()
	public memoriet: Memoriet | null;

	@Index()
	@Column(id())
	public viewerId: User["id"];

	@ManyToOne(() => User, { onDelete: "CASCADE" })
	@JoinColumn()
	public viewer: User | null;
}
