const sequelize = require('../../../routes/db-config');
const { DataTypes } = require('sequelize');
const { Property } = require('../property');
const { Category } = require('./category');
const { City } = require('./city');
const { TypeProperty } = require('./typeProperty');
const PropertySpecification = sequelize.define('propertySpecification', {
id: {
type: DataTypes.BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
},
propertyId: {
type: DataTypes.BIGINT(20).UNSIGNED,
allowNull: false,
references: {
model: 'property',
key: 'id',
},
},
typePropertyId: {
type: DataTypes.BIGINT(20).UNSIGNED,
allowNull: true,
references: {
model: 'typeProperty',
key: 'id',
},
},
categoryId: {
type: DataTypes.BIGINT(20).UNSIGNED,
allowNull: true,
references: {
model: 'category',
key: 'id',
},
},
cityId: {
type: DataTypes.BIGINT(20).UNSIGNED,
allowNull: true,
references: {
model: 'city',
key: 'id',
},
},
bedrooms: {
type: DataTypes.INTEGER,
allowNull: false,
},
bathrooms: {
type: DataTypes.INTEGER,
allowNull: false,
},
area: {
type: DataTypes.STRING(255),
allowNull: false,
},
map: {
type: DataTypes.STRING(255),
allowNull: false,
},
dateAvailable: {
type: DataTypes.STRING(255),
allowNull: true,
},
size: {
type: DataTypes.FLOAT(20).UNSIGNED,
allowNull: false,
},
quality: {
type: DataTypes.STRING(30),
allowNull: false,
},
view: {
type: DataTypes.STRING(30),
allowNull: true,
},
parking: {
type: DataTypes.STRING(30),
allowNull: true,
},
conditioner: {
type: DataTypes.STRING(30),
allowNull: true,
},
balcony: {
type: DataTypes.STRING(30),
allowNull: true,
},
pool: {
type: DataTypes.STRING(30),
allowNull: true,
},
steamRoom: {
type: DataTypes.STRING(30),
allowNull: true,
},
gym: {
type: DataTypes.STRING(30),
allowNull: true,
},
security: {
type: DataTypes.STRING(30),
allowNull: true,
},
maintenance: {
type: DataTypes.STRING(30),
allowNull: true,
},
floor: {
type: DataTypes.STRING(30),
allowNull: true,
},
near: {
type: DataTypes.TEXT('long'),
allowNull: true,
},
Description: {
type: DataTypes.TEXT('long'),
allowNull: true,
},
imageUrl: {
type: DataTypes.TEXT('long'),
allowNull: false,
},
});
PropertySpecification.hasOne(TypeProperty, {
foreignKey: 'typePropertyId',
onDelete: 'SET NULL',
});
TypeProperty.belongsTo(PropertySpecification, {
foreignKey: 'propertySpecificationId',
onDelete: 'SET NULL',
});
PropertySpecification.hasOne(Category, {
foreignKey: 'categoryId',
onDelete: 'SET NULL',
});
Category.belongsTo(PropertySpecification, {
foreignKey: 'propertySpecificationId',
onDelete: 'SET NULL',
});
PropertySpecification.hasOne(City, {
foreignKey: 'cityId',
onDelete: 'SET NULL',
});
City.belongsTo(PropertySpecification, {
foreignKey: 'propertySpecificationId',
onDelete: 'SET NULL',
});
module.exports = {
PropertySpecification,
};