import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { Permission, PermissionId } from './Permission';
import type { Role, RoleId } from './Role';
import type { User, UserId } from './User';
export interface RolePermissionAttributes {
	id: string;
	role_id: string;
	permission_id: string;
	created_at?: Date | null;
	created_by?: string | null;
	updated_by?: string | null;
	updated_at?: Date | null;
}
export type RolePermissionPk = 'id';
export type RolePermissionId = RolePermission[RolePermissionPk];
export type RolePermissionOptionalAttributes = 'id' | 'created_at' | 'created_by' | 'updated_by' | 'updated_at';
export type RolePermissionCreationAttributes = Optional<RolePermissionAttributes, RolePermissionOptionalAttributes>;
export class RolePermission extends Model<RolePermissionAttributes> implements RolePermissionAttributes {
	declare id: string;
	declare role_id: string;
	declare permission_id: string;
	declare created_at?: Date | null;
	declare created_by?: string | null;
	declare updated_by?: string | null;
	declare updated_at?: Date | null;
	// RolePermission belongsTo Permission via permission_id
	declare permission: Permission;
	declare getPermission: Sequelize.BelongsToGetAssociationMixin<Permission>;
	declare setPermission: Sequelize.BelongsToSetAssociationMixin<Permission, PermissionId>;
	declare createPermission: Sequelize.BelongsToCreateAssociationMixin<Permission>;
	// RolePermission belongsTo Role via role_id
	declare role: Role;
	declare getRole: Sequelize.BelongsToGetAssociationMixin<Role>;
	declare setRole: Sequelize.BelongsToSetAssociationMixin<Role, RoleId>;
	declare createRole: Sequelize.BelongsToCreateAssociationMixin<Role>;
	// RolePermission 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>;
	// RolePermission 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 RolePermission {
		return RolePermission.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				role_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'roles',
						key: 'id',
					},
					unique: 'role_permissions_role_id_permission_id_key',
				},
				permission_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'permissions',
						key: 'id',
					},
					unique: 'role_permissions_role_id_permission_id_key',
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				created_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				updated_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'role_permissions',
				schema: 'public',
				hasTrigger: true,
				timestamps: false,
				indexes: [
					{
						name: 'idx_role_permissions_permission_id',
						fields: [{ name: 'permission_id' }],
					},
					{
						name: 'idx_role_permissions_role_id',
						fields: [{ name: 'role_id' }],
					},
					{
						name: 'role_permissions_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'role_permissions_role_id_permission_id_key',
						unique: true,
						fields: [{ name: 'role_id' }, { name: 'permission_id' }],
					},
				],
			},
		);
	}
}
