import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { Bill, BillId } from './Bill';
export interface BillItemAttributes {
	id: string;
	bill_id: string;
	fee_name: string;
	quantity: number;
	unit_price: number;
	created_at?: Date | null;
}
export type BillItemPk = 'id';
export type BillItemId = BillItem[BillItemPk];
export type BillItemOptionalAttributes = 'id' | 'quantity' | 'created_at';
export type BillItemCreationAttributes = Optional<BillItemAttributes, BillItemOptionalAttributes>;
export class BillItem extends Model<BillItemAttributes> implements BillItemAttributes {
	declare id: string;
	declare bill_id: string;
	declare fee_name: string;
	declare quantity: number;
	declare unit_price: number;
	declare created_at?: Date | null;
	// BillItem belongsTo Bill via bill_id
	declare bill: Bill;
	declare getBill: Sequelize.BelongsToGetAssociationMixin<Bill>;
	declare setBill: Sequelize.BelongsToSetAssociationMixin<Bill, BillId>;
	declare createBill: Sequelize.BelongsToCreateAssociationMixin<Bill>;
	static initModel(sequelize: Sequelize.Sequelize): typeof BillItem {
		return BillItem.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				bill_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'bills',
						key: 'id',
					},
				},
				fee_name: {
					type: DataTypes.STRING(255),
					allowNull: false,
				},
				quantity: {
					type: DataTypes.INTEGER,
					allowNull: false,
					defaultValue: 1,
				},
				unit_price: {
					type: DataTypes.DECIMAL,
					allowNull: false,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'bill_items',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'bill_items_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
