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 TechnicianAttributes {
	id: string;
	specialty: string;
	status: 'active' | 'inactive' | 'on_leave' | 'terminated';
	avatar_id?: string | null;
	notes?: string | null;
	deleted_at?: Date | null;
	deleted_by?: string | null;
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
	user_id?: string | null;
}
export type TechnicianPk = 'id';
export type TechnicianId = Technician[TechnicianPk];
export type TechnicianOptionalAttributes =
	| 'id'
	| 'status'
	| 'avatar_id'
	| 'notes'
	| 'deleted_at'
	| 'deleted_by'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at'
	| 'user_id';
export type TechnicianCreationAttributes = Optional<TechnicianAttributes, TechnicianOptionalAttributes>;
export class Technician extends Model<TechnicianAttributes> implements TechnicianAttributes {
	declare id: string;
	declare specialty: string;
	declare status: 'active' | 'inactive' | 'on_leave' | 'terminated';
	declare avatar_id?: string | null;
	declare notes?: 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;
	declare user_id?: string | null;
	// Technician belongsTo File via avatar_id
	declare avatar: File;
	declare getAvatar: Sequelize.BelongsToGetAssociationMixin<File>;
	declare setAvatar: Sequelize.BelongsToSetAssociationMixin<File, FileId>;
	declare createAvatar: Sequelize.BelongsToCreateAssociationMixin<File>;
	// Technician hasMany Incident via technician_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;
	// Technician 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>;
	// Technician 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>;
	// Technician 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>;
	// Technician belongsTo User via user_id
	declare user: User;
	declare getUser: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setUser: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createUser: Sequelize.BelongsToCreateAssociationMixin<User>;
	static initModel(sequelize: Sequelize.Sequelize): typeof Technician {
		return Technician.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				specialty: {
					type: DataTypes.STRING(100),
					allowNull: false,
				},
				status: {
					type: DataTypes.ENUM('active', 'inactive', 'on_leave', 'terminated'),
					allowNull: false,
					defaultValue: 'active',
				},
				avatar_id: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'files',
						key: 'id',
					},
				},
				notes: {
					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'),
				},
				user_id: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
			},
			{
				sequelize,
				tableName: 'technicians',
				schema: 'public',
				timestamps: false,

				scopes: {
					default: {
						where: {
							deleted_at: null,
						},
					},
					withDeleted: {},
					onlyDeleted: {
						where: {
							deleted_at: { [Op.ne]: null },
						},
					},
				},
				indexes: [
					{
						name: 'idx_technicians_specialty',
						fields: [{ name: 'specialty' }],
					},
					{
						name: 'idx_technicians_status',
						fields: [{ name: 'status' }],
					},
					{
						name: 'idx_technicians_user_id',
						fields: [{ name: 'user_id' }],
					},
					{
						name: 'technicians_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
