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

export type MemorietTextLayer = {
	id: string;
	text: string;
	color: string;
	backgroundColor: string | null;
	backgroundWidth: number | null;
	backgroundHeight: number | null;
	fontSize: number;
	x: number;
	y: number;
	rotate: number;
};

@Entity("memoriet")
export class Memoriet {
	@PrimaryColumn(id())
	public id: string;

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

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

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

	@Index()
	@Column(id())
	public noteId: Note["id"];

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

	@Index()
	@Column("timestamp with time zone", { nullable: true })
	public expiresAt: Date | null;

	@Column("jsonb", { default: [] })
	public textLayers: MemorietTextLayer[];
}
