import * as Sequelize from 'sequelize';
import { Op } from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { Incident, IncidentId } from './Incident';
import type { User, UserId } from './User';
export interface IncidentTypeAttributes {
	id: string;
	name: string;
	description?: string | null;
	deleted_at?: Date | null;
	deleted_by?: string | null;
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type IncidentTypePk = 'id';
export type IncidentTypeId = IncidentType[IncidentTypePk];
export type IncidentTypeOptionalAttributes =
	| 'id'
	| 'description'
	| 'deleted_at'
	| 'deleted_by'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type IncidentTypeCreationAttributes = Optional<IncidentTypeAttributes, IncidentTypeOptionalAttributes>;
export class IncidentType extends Model<IncidentTypeAttributes> implements IncidentTypeAttributes {
	declare id: string;
	declare name: string;
	declare description?: string | null;
	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;
	// IncidentType hasMany Incident via type_id
	declare incidents: Incident[];
	declare getIncidents: Sequelize.HasManyGetAssociationsMixin<Incident>;
	declare setIncidents: Sequelize.HasManySetAssociationsMixin<Incident, IncidentId>;
	declare addIncident: Sequelize.HasManyAddAssociationMixin<Incident, IncidentId>;
	declare addIncidents: Sequelize.HasManyAddAssociationsMixin<Incident, IncidentId>;
	declare createIncident: Sequelize.HasManyCreateAssociationMixin<Incident>;
	declare removeIncident: Sequelize.HasManyRemoveAssociationMixin<Incident, IncidentId>;
	declare removeIncidents: Sequelize.HasManyRemoveAssociationsMixin<Incident, IncidentId>;
	declare hasIncident: Sequelize.HasManyHasAssociationMixin<Incident, IncidentId>;
	declare hasIncidents: Sequelize.HasManyHasAssociationsMixin<Incident, IncidentId>;
	declare countIncidents: Sequelize.HasManyCountAssociationsMixin;
	// IncidentType 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>;
	// IncidentType 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>;
	// IncidentType 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 IncidentType {
		return IncidentType.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				name: {
					type: DataTypes.STRING(100),
					allowNull: false,
				},
				description: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				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_types',
				schema: 'public',
				timestamps: false,

				scopes: {
					default: {
						where: {
							deleted_at: null,
						},
					},
					withDeleted: {},
					onlyDeleted: {
						where: {
							deleted_at: { [Op.ne]: null },
						},
					},
				},
				indexes: [
					{
						name: 'idx_incident_types_name',
						unique: true,
						fields: [{ name: 'name' }],
					},
					{
						name: 'incident_types_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
