import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { File, FileId } from './File';
export interface FileVariantAttributes {
	id: string;
	file_id: string;
	variant_name: string;
	provider: 'local' | 'minio' | 's3';
	bucket_name: string;
	object_key: string;
	mime_type?: string | null;
	size_bytes?: number | null;
	width?: number | null;
	height?: number | null;
	created_at: Date;
}
export type FileVariantPk = 'id';
export type FileVariantId = FileVariant[FileVariantPk];
export type FileVariantOptionalAttributes =
	| 'id'
	| 'provider'
	| 'bucket_name'
	| 'mime_type'
	| 'size_bytes'
	| 'width'
	| 'height'
	| 'created_at';
export type FileVariantCreationAttributes = Optional<FileVariantAttributes, FileVariantOptionalAttributes>;
export class FileVariant extends Model<FileVariantAttributes> implements FileVariantAttributes {
	declare id: string;
	declare file_id: string;
	declare variant_name: string;
	declare provider: 'local' | 'minio' | 's3';
	declare bucket_name: string;
	declare object_key: string;
	declare mime_type?: string | null;
	declare size_bytes?: number | null;
	declare width?: number | null;
	declare height?: number | null;
	declare created_at: Date;
	// FileVariant belongsTo File via file_id
	declare file: File;
	declare getFile: Sequelize.BelongsToGetAssociationMixin<File>;
	declare setFile: Sequelize.BelongsToSetAssociationMixin<File, FileId>;
	declare createFile: Sequelize.BelongsToCreateAssociationMixin<File>;
	static initModel(sequelize: Sequelize.Sequelize): typeof FileVariant {
		return FileVariant.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				file_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'files',
						key: 'id',
					},
					unique: 'uq_file_variant',
				},
				variant_name: {
					type: DataTypes.STRING(50),
					allowNull: false,
					unique: 'uq_file_variant',
				},
				provider: {
					type: DataTypes.ENUM('local', 'minio', 's3'),
					allowNull: false,
					defaultValue: 'local',
					unique: 'uq_variant_storage_location',
				},
				bucket_name: {
					type: DataTypes.STRING(100),
					allowNull: false,
					defaultValue: '',
					unique: 'uq_variant_storage_location',
				},
				object_key: {
					type: DataTypes.TEXT,
					allowNull: false,
					unique: 'uq_variant_storage_location',
				},
				mime_type: {
					type: DataTypes.STRING(100),
					allowNull: true,
				},
				size_bytes: {
					type: DataTypes.BIGINT,
					allowNull: true,
				},
				width: {
					type: DataTypes.INTEGER,
					allowNull: true,
				},
				height: {
					type: DataTypes.INTEGER,
					allowNull: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.fn('now'),
				},
			},
			{
				sequelize,
				tableName: 'file_variants',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'file_variants_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'idx_file_variants_file_created',
						fields: [{ name: 'file_id' }, { name: 'created_at', order: 'DESC' }],
					},
					{
						name: 'uq_file_variant',
						unique: true,
						fields: [{ name: 'file_id' }, { name: 'variant_name' }],
					},
					{
						name: 'uq_variant_storage_location',
						unique: true,
						fields: [{ name: 'provider' }, { name: 'bucket_name' }, { name: 'object_key' }],
					},
				],
			},
		);
	}
}
