import * as Sequelize from 'sequelize';
import { DataTypes, Model } from 'sequelize';
import type { Post, PostId } from './Post';
export interface PostTargetAttributes {
	post_id: string;
	target_id: string;
}
export type PostTargetPk = 'post_id' | 'target_id';
export type PostTargetId = PostTarget[PostTargetPk];
export type PostTargetCreationAttributes = PostTargetAttributes;
export class PostTarget extends Model<PostTargetAttributes> implements PostTargetAttributes {
	declare post_id: string;
	declare target_id: string;
	// PostTarget belongsTo Post via post_id
	declare post: Post;
	declare getPost: Sequelize.BelongsToGetAssociationMixin<Post>;
	declare setPost: Sequelize.BelongsToSetAssociationMixin<Post, PostId>;
	declare createPost: Sequelize.BelongsToCreateAssociationMixin<Post>;
	static initModel(sequelize: Sequelize.Sequelize): typeof PostTarget {
		return PostTarget.init(
			{
				post_id: {
					type: DataTypes.UUID,
					allowNull: false,
					primaryKey: true,
					references: {
						model: 'posts',
						key: 'id',
					},
				},
				target_id: {
					type: DataTypes.UUID,
					allowNull: false,
					primaryKey: true,
				},
			},
			{
				sequelize,
				tableName: 'post_targets',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_post_targets_target_id',
						fields: [{ name: 'target_id' }],
					},
					{
						name: 'post_targets_pkey',
						unique: true,
						fields: [{ name: 'post_id' }, { name: 'target_id' }],
					},
				],
			},
		);
	}
}
