import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { DebtReminderPolicy, DebtReminderPolicyId } from './DebtReminderPolicy';
export interface DebtReminderPolicyTargetAttributes {
	id: string;
	policy_id: string;
	target_type: string;
	target_id?: string | null;
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type DebtReminderPolicyTargetPk = 'id';
export type DebtReminderPolicyTargetId = DebtReminderPolicyTarget[DebtReminderPolicyTargetPk];
export type DebtReminderPolicyTargetOptionalAttributes =
	| 'id'
	| 'target_id'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type DebtReminderPolicyTargetCreationAttributes = Optional<
	DebtReminderPolicyTargetAttributes,
	DebtReminderPolicyTargetOptionalAttributes
>;
export class DebtReminderPolicyTarget
	extends Model<DebtReminderPolicyTargetAttributes>
	implements DebtReminderPolicyTargetAttributes
{
	declare id: string;
	declare policy_id: string;
	declare target_type: string;
	declare target_id?: string | null;
	declare created_by?: string | null;
	declare updated_by?: string | null;
	declare created_at: Date;
	declare updated_at: Date;
	// DebtReminderPolicyTarget belongsTo DebtReminderPolicy via policy_id
	declare policy: DebtReminderPolicy;
	declare getPolicy: Sequelize.BelongsToGetAssociationMixin<DebtReminderPolicy>;
	declare setPolicy: Sequelize.BelongsToSetAssociationMixin<DebtReminderPolicy, DebtReminderPolicyId>;
	declare createPolicy: Sequelize.BelongsToCreateAssociationMixin<DebtReminderPolicy>;
	static initModel(sequelize: Sequelize.Sequelize): typeof DebtReminderPolicyTarget {
		return DebtReminderPolicyTarget.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				policy_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'debt_reminder_policies',
						key: 'id',
					},
				},
				target_type: {
					type: DataTypes.STRING(20),
					allowNull: false,
				},
				target_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				created_by: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				updated_by: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.fn('now'),
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.fn('now'),
				},
			},
			{
				sequelize,
				tableName: 'debt_reminder_policy_targets',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'debt_reminder_policy_targets_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'idx_policy_targets_policy_id',
						fields: [{ name: 'policy_id' }],
					},
					{
						name: 'idx_policy_targets_target_id',
						fields: [{ name: 'target_id' }],
					},
					{
						name: 'idx_policy_targets_target_type_id',
						fields: [{ name: 'target_type' }, { name: 'target_id' }],
					},
				],
			},
		);
	}
}
