import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
export interface SystemConfigAttributes {
	id: string;
	config_key: string;
	config_group: string;
	description?: string | null;
	config_value: object;
	is_active: boolean;
	created_at: Date;
	updated_at: Date;
}
export type SystemConfigPk = 'id';
export type SystemConfigId = SystemConfig[SystemConfigPk];
export type SystemConfigOptionalAttributes = 'id' | 'description' | 'is_active' | 'created_at' | 'updated_at';
export type SystemConfigCreationAttributes = Optional<SystemConfigAttributes, SystemConfigOptionalAttributes>;
export class SystemConfig extends Model<SystemConfigAttributes> implements SystemConfigAttributes {
	declare id: string;
	declare config_key: string;
	declare config_group: string;
	declare description?: string | null;
	declare config_value: object;
	declare is_active: boolean;
	declare created_at: Date;
	declare updated_at: Date;
	static initModel(sequelize: Sequelize.Sequelize): typeof SystemConfig {
		return SystemConfig.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				config_key: {
					type: DataTypes.STRING(100),
					allowNull: false,
					unique: 'system_configs_config_key_key',
				},
				config_group: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				description: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				config_value: {
					type: DataTypes.JSONB,
					allowNull: false,
				},
				is_active: {
					type: DataTypes.BOOLEAN,
					allowNull: false,
					defaultValue: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.fn('now'),
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.fn('now'),
				},
			},
			{
				sequelize,
				tableName: 'system_configs',
				schema: 'public',
				hasTrigger: true,
				timestamps: false,
				indexes: [
					{
						name: 'idx_system_configs_group',
						fields: [{ name: 'config_group' }],
					},
					{
						name: 'idx_system_configs_group_active',
						fields: [{ name: 'config_group' }, { name: 'is_active' }],
					},
					{
						name: 'system_configs_config_key_key',
						unique: true,
						fields: [{ name: 'config_key' }],
					},
					{
						name: 'system_configs_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
