import * as Sequelize from 'sequelize';
import { Op } from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { File, FileId } from './File';
import type { Incident, IncidentId } from './Incident';
import type { User, UserId } from './User';
export interface IncidentFileAttributes {
	id: string;
	incident_id: string;
	file_id: string;
	deleted_at?: Date | null;
	deleted_by?: string | null;
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type IncidentFilePk = 'id';
export type IncidentFileId = IncidentFile[IncidentFilePk];
export type IncidentFileOptionalAttributes =
	| 'id'
	| 'deleted_at'
	| 'deleted_by'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type IncidentFileCreationAttributes = Optional<IncidentFileAttributes, IncidentFileOptionalAttributes>;
export class IncidentFile extends Model<IncidentFileAttributes> implements IncidentFileAttributes {
	declare id: string;
	declare incident_id: string;
	declare file_id: string;
	declare deleted_at?: Date | null;
	declare deleted_by?: string | null;
	declare created_by?: string | null;
	declare updated_by?: string | null;
	declare created_at: Date;
	declare updated_at: Date;
	// IncidentFile belongsTo File via file_id
	declare file: File;
	declare getFile: Sequelize.BelongsToGetAssociationMixin<File>;
	declare setFile: Sequelize.BelongsToSetAssociationMixin<File, FileId>;
	declare createFile: Sequelize.BelongsToCreateAssociationMixin<File>;
	// IncidentFile belongsTo Incident via incident_id
	declare incident: Incident;
	declare getIncident: Sequelize.BelongsToGetAssociationMixin<Incident>;
	declare setIncident: Sequelize.BelongsToSetAssociationMixin<Incident, IncidentId>;
	declare createIncident: Sequelize.BelongsToCreateAssociationMixin<Incident>;
	// IncidentFile belongsTo User via created_by
	declare created_by_user: User;
	declare getCreated_by_user: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setCreated_by_user: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createCreated_by_user: Sequelize.BelongsToCreateAssociationMixin<User>;
	// IncidentFile belongsTo User via deleted_by
	declare deleted_by_user: User;
	declare getDeleted_by_user: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setDeleted_by_user: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createDeleted_by_user: Sequelize.BelongsToCreateAssociationMixin<User>;
	// IncidentFile belongsTo User via updated_by
	declare updated_by_user: User;
	declare getUpdated_by_user: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setUpdated_by_user: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createUpdated_by_user: Sequelize.BelongsToCreateAssociationMixin<User>;
	static initModel(sequelize: Sequelize.Sequelize): typeof IncidentFile {
		return IncidentFile.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				incident_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'incidents',
						key: 'id',
					},
				},
				file_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'files',
						key: 'id',
					},
				},
				deleted_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				deleted_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				created_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				updated_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'incident_files',
				schema: 'public',
				timestamps: false,

				scopes: {
					default: {
						where: {
							deleted_at: null,
						},
					},
					withDeleted: {},
					onlyDeleted: {
						where: {
							deleted_at: { [Op.ne]: null },
						},
					},
				},
				indexes: [
					{
						name: 'idx_incident_files_file_id',
						fields: [{ name: 'file_id' }],
					},
					{
						name: 'idx_incident_files_incident_id',
						fields: [{ name: 'incident_id' }],
					},
					{
						name: 'incident_files_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
