import * as Sequelize from 'sequelize';
import { Op } from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { Contract, ContractId } from './Contract';
import type { File, FileId } from './File';
import type { User, UserId } from './User';
export interface ContractFileAttributes {
	id: string;
	contract_id: string;
	file_id: string;
	created_by?: string | null;
	updated_by?: string | null;
	deleted_at?: Date | null;
	deleted_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type ContractFilePk = 'id';
export type ContractFileId = ContractFile[ContractFilePk];
export type ContractFileOptionalAttributes =
	| 'id'
	| 'created_by'
	| 'updated_by'
	| 'deleted_at'
	| 'deleted_by'
	| 'created_at'
	| 'updated_at';
export type ContractFileCreationAttributes = Optional<ContractFileAttributes, ContractFileOptionalAttributes>;
export class ContractFile extends Model<ContractFileAttributes> implements ContractFileAttributes {
	declare id: string;
	declare contract_id: string;
	declare file_id: string;
	declare created_by?: string | null;
	declare updated_by?: string | null;
	declare deleted_at?: Date | null;
	declare deleted_by?: string | null;
	declare created_at: Date;
	declare updated_at: Date;
	// ContractFile belongsTo Contract via contract_id
	declare contract: Contract;
	declare getContract: Sequelize.BelongsToGetAssociationMixin<Contract>;
	declare setContract: Sequelize.BelongsToSetAssociationMixin<Contract, ContractId>;
	declare createContract: Sequelize.BelongsToCreateAssociationMixin<Contract>;
	// ContractFile belongsTo File via file_id
	declare file: File;
	declare getFile: Sequelize.BelongsToGetAssociationMixin<File>;
	declare setFile: Sequelize.BelongsToSetAssociationMixin<File, FileId>;
	declare createFile: Sequelize.BelongsToCreateAssociationMixin<File>;
	// ContractFile 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>;
	// ContractFile 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>;
	// ContractFile 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 ContractFile {
		return ContractFile.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				contract_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'contracts',
						key: 'id',
					},
				},
				file_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'files',
						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',
					},
				},
				deleted_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				deleted_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_files',
				schema: 'public',
				timestamps: false,

				scopes: {
					default: {
						where: {
							deleted_at: null,
						},
					},
					withDeleted: {},
					onlyDeleted: {
						where: {
							deleted_at: { [Op.ne]: null },
						},
					},
				},
				indexes: [
					{
						name: 'contract_files_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'idx_contract_files_contract_id',
						fields: [{ name: 'contract_id' }],
					},
					{
						name: 'idx_contract_files_file_id',
						fields: [{ name: 'file_id' }],
					},
				],
			},
		);
	}
}
