import * as Sequelize from 'sequelize';
import { Op } from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { ResidentStay, ResidentStayId } from './ResidentStay';
import type { Room, RoomId } from './Room';
import type { User, UserId } from './User';
export interface BedAttributes {
	id: string;
	room_id: string;
	name: string;
	code: string;
	status: 'active' | 'inactive';
	deleted_at?: Date | null;
	deleted_by?: string | null;
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type BedPk = 'id';
export type BedId = Bed[BedPk];
export type BedOptionalAttributes =
	| 'id'
	| 'status'
	| 'deleted_at'
	| 'deleted_by'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type BedCreationAttributes = Optional<BedAttributes, BedOptionalAttributes>;
export class Bed extends Model<BedAttributes> implements BedAttributes {
	declare id: string;
	declare room_id: string;
	declare name: string;
	declare code: string;
	declare status: 'active' | 'inactive';
	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;
	// Bed hasMany ResidentStay via bed_id
	declare resident_stays: ResidentStay[];
	declare getResident_stays: Sequelize.HasManyGetAssociationsMixin<ResidentStay>;
	declare setResident_stays: Sequelize.HasManySetAssociationsMixin<ResidentStay, ResidentStayId>;
	declare addResident_stay: Sequelize.HasManyAddAssociationMixin<ResidentStay, ResidentStayId>;
	declare addResident_stays: Sequelize.HasManyAddAssociationsMixin<ResidentStay, ResidentStayId>;
	declare createResident_stay: Sequelize.HasManyCreateAssociationMixin<ResidentStay>;
	declare removeResident_stay: Sequelize.HasManyRemoveAssociationMixin<ResidentStay, ResidentStayId>;
	declare removeResident_stays: Sequelize.HasManyRemoveAssociationsMixin<ResidentStay, ResidentStayId>;
	declare hasResident_stay: Sequelize.HasManyHasAssociationMixin<ResidentStay, ResidentStayId>;
	declare hasResident_stays: Sequelize.HasManyHasAssociationsMixin<ResidentStay, ResidentStayId>;
	declare countResident_stays: Sequelize.HasManyCountAssociationsMixin;
	// Bed belongsTo Room via room_id
	declare room: Room;
	declare getRoom: Sequelize.BelongsToGetAssociationMixin<Room>;
	declare setRoom: Sequelize.BelongsToSetAssociationMixin<Room, RoomId>;
	declare createRoom: Sequelize.BelongsToCreateAssociationMixin<Room>;
	// Bed 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>;
	// Bed 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>;
	// Bed 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 Bed {
		return Bed.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				room_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'rooms',
						key: 'id',
					},
				},
				name: {
					type: DataTypes.STRING(200),
					allowNull: false,
				},
				code: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				status: {
					type: DataTypes.ENUM('active', 'inactive'),
					allowNull: false,
					defaultValue: 'active',
				},
				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: 'beds',
				schema: 'public',
				hasTrigger: true,
				timestamps: false,

				scopes: {
					default: {
						where: {
							deleted_at: null,
						},
					},
					withDeleted: {},
					onlyDeleted: {
						where: {
							deleted_at: { [Op.ne]: null },
						},
					},
				},
				indexes: [
					{
						name: 'beds_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'idx_beds_code',
						fields: [{ name: 'code' }],
					},
					{
						name: 'idx_beds_deleted_at',
						fields: [{ name: 'deleted_at' }],
					},
					{
						name: 'idx_beds_room_id',
						fields: [{ name: 'room_id' }],
					},
					{
						name: 'idx_beds_status',
						fields: [{ name: 'status' }],
					},
					{
						name: 'uq_beds_code',
						unique: true,
						fields: [{ name: 'room_id' }, { name: 'code' }],
					},
				],
			},
		);
	}
}
