import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { Bed, BedId } from './Bed';
import type { Resident, ResidentId } from './Resident';
import type { User, UserId } from './User';
export interface ResidentStayAttributes {
	id: string;
	resident_id: string;
	bed_id: string;
	move_in_at: Date;
	move_out_at?: Date | null;
	occupancy_period?: string[] | null;
	move_out_reason?: string | null;
	move_out_notes?: string | null;
	stay_type: 'permanent' | 'temporary' | 'maintenance' | 'quarantine' | 'guest';
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type ResidentStayPk = 'id';
export type ResidentStayId = ResidentStay[ResidentStayPk];
export type ResidentStayOptionalAttributes =
	| 'id'
	| 'move_in_at'
	| 'move_out_at'
	| 'occupancy_period'
	| 'move_out_reason'
	| 'move_out_notes'
	| 'stay_type'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type ResidentStayCreationAttributes = Optional<ResidentStayAttributes, ResidentStayOptionalAttributes>;
export class ResidentStay extends Model<ResidentStayAttributes> implements ResidentStayAttributes {
	declare id: string;
	declare resident_id: string;
	declare bed_id: string;
	declare move_in_at: Date;
	declare move_out_at?: Date | null;
	declare occupancy_period?: string[] | null;
	declare move_out_reason?: string | null;
	declare move_out_notes?: string | null;
	declare stay_type: 'permanent' | 'temporary' | 'maintenance' | 'quarantine' | 'guest';
	declare created_by?: string | null;
	declare updated_by?: string | null;
	declare created_at: Date;
	declare updated_at: Date;
	// ResidentStay belongsTo Bed via bed_id
	declare bed: Bed;
	declare getBed: Sequelize.BelongsToGetAssociationMixin<Bed>;
	declare setBed: Sequelize.BelongsToSetAssociationMixin<Bed, BedId>;
	declare createBed: Sequelize.BelongsToCreateAssociationMixin<Bed>;
	// ResidentStay belongsTo Resident via resident_id
	declare resident: Resident;
	declare getResident: Sequelize.BelongsToGetAssociationMixin<Resident>;
	declare setResident: Sequelize.BelongsToSetAssociationMixin<Resident, ResidentId>;
	declare createResident: Sequelize.BelongsToCreateAssociationMixin<Resident>;
	// ResidentStay 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>;
	// ResidentStay 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 ResidentStay {
		return ResidentStay.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				resident_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'residents',
						key: 'id',
					},
				},
				bed_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'beds',
						key: 'id',
					},
				},
				move_in_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				move_out_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				occupancy_period: {
					type: DataTypes.RANGE(DataTypes.DATE),
					allowNull: true,
					comment: 'Generated tstzrange column for time-range queries. Inclusive start, exclusive end.',
				},
				move_out_reason: {
					type: DataTypes.STRING(255),
					allowNull: true,
					comment: 'Required when move_out_at is set. Enforced by CHECK constraint.',
				},
				move_out_notes: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				stay_type: {
					type: DataTypes.ENUM('permanent', 'temporary', 'maintenance', 'quarantine', 'guest'),
					allowNull: false,
					defaultValue: 'permanent',
				},
				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: 'resident_stays',
				schema: 'public',
				hasTrigger: true,
				timestamps: false,
				indexes: [
					{
						name: 'idx_resident_stays_active_bed_partial',
						fields: [{ name: 'bed_id' }],
					},
					{
						name: 'idx_resident_stays_active_resident_partial',
						fields: [{ name: 'resident_id' }],
					},
					{
						name: 'idx_resident_stays_bed_id',
						fields: [{ name: 'bed_id' }],
					},
					{
						name: 'idx_resident_stays_move_in_at',
						fields: [{ name: 'move_in_at' }],
					},
					{
						name: 'idx_resident_stays_move_out_at',
						fields: [{ name: 'move_out_at' }],
					},
					{
						name: 'idx_resident_stays_occupancy_period',
						fields: [{ name: 'occupancy_period' }],
					},
					{
						name: 'idx_resident_stays_resident_id',
						fields: [{ name: 'resident_id' }],
					},
					{
						name: 'resident_stays_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
