import * as Sequelize from 'sequelize';
import { Op } from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { Contract, ContractId } from './Contract';
import type { User, UserId } from './User';
export interface ContractTypeAttributes {
	id: string;
	code: string;
	name_vi: string;
	name_en?: string | null;
	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 ContractTypePk = 'id';
export type ContractTypeId = ContractType[ContractTypePk];
export type ContractTypeOptionalAttributes =
	| 'id'
	| 'name_en'
	| 'description'
	| 'deleted_at'
	| 'deleted_by'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type ContractTypeCreationAttributes = Optional<ContractTypeAttributes, ContractTypeOptionalAttributes>;
export class ContractType extends Model<ContractTypeAttributes> implements ContractTypeAttributes {
	declare id: string;
	declare code: string;
	declare name_vi: string;
	declare name_en?: string | null;
	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;
	// ContractType hasMany Contract via contract_type_id
	declare contracts: Contract[];
	declare getContracts: Sequelize.HasManyGetAssociationsMixin<Contract>;
	declare setContracts: Sequelize.HasManySetAssociationsMixin<Contract, ContractId>;
	declare addContract: Sequelize.HasManyAddAssociationMixin<Contract, ContractId>;
	declare addContracts: Sequelize.HasManyAddAssociationsMixin<Contract, ContractId>;
	declare createContract: Sequelize.HasManyCreateAssociationMixin<Contract>;
	declare removeContract: Sequelize.HasManyRemoveAssociationMixin<Contract, ContractId>;
	declare removeContracts: Sequelize.HasManyRemoveAssociationsMixin<Contract, ContractId>;
	declare hasContract: Sequelize.HasManyHasAssociationMixin<Contract, ContractId>;
	declare hasContracts: Sequelize.HasManyHasAssociationsMixin<Contract, ContractId>;
	declare countContracts: Sequelize.HasManyCountAssociationsMixin;
	// ContractType 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>;
	// ContractType 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>;
	// ContractType 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 ContractType {
		return ContractType.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				code: {
					type: DataTypes.STRING(50),
					allowNull: false,
					unique: 'contract_types_code_key',
				},
				name_vi: {
					type: DataTypes.STRING(100),
					allowNull: false,
				},
				name_en: {
					type: DataTypes.STRING(100),
					allowNull: true,
				},
				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: 'contract_types',
				schema: 'public',
				hasTrigger: true,
				timestamps: false,

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