"use strict";

const { AD_TYPE, EMAIL_FREQUENCY } = require("../common/enums");

module.exports = (sequelize, DataTypes) => {
  const SearchRequest = sequelize.define("SearchRequest", {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      allowNull: false,
      primaryKey: true
    },
    areaToSearch: {
      type: DataTypes.GEOMETRY("POLYGON", 4326),
      allowNull: false,
      defaultValue: {
        type: "Polygon",
        coordinates: [
          [
            [0, 0],
            [0, 0],
            [0, 0],
            [0, 0],
            [0, 0]
          ]
        ],
        crs: { type: "name", properties: { name: "EPSG:4326" } }
      }
    },
    realEstateType: {
      type: DataTypes.TEXT,
      allowNull: false
    },
    adType: {
      type: DataTypes.TEXT,
      allowNull: false,
      defaultValue: AD_TYPE.AD_TYPE_SALE.stringId
    },
    email: DataTypes.TEXT,
    locality: DataTypes.TEXT,
    municipality: DataTypes.TEXT,
    city: DataTypes.TEXT,
    region: DataTypes.TEXT,
    entity: DataTypes.TEXT,
    country: DataTypes.TEXT,
    sizeMin: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    sizeMax: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    priceMin: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    priceMax: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    gardenSizeMin: DataTypes.INTEGER,
    gardenSizeMax: DataTypes.INTEGER,
    subscribed: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      allowNull: false
    },
    emailFrequency: {
      type: DataTypes.TEXT,
      defaultValue: EMAIL_FREQUENCY.ASAP.stringId,
      allowNull: false
    },
    deletedEmail: {
      type: DataTypes.TEXT
    },
    includeIncompleteAds: DataTypes.BOOLEAN,
    includeWithoutPrice: DataTypes.BOOLEAN,
    balcony: DataTypes.BOOLEAN,
    elevator: DataTypes.BOOLEAN,
    newBuilding: DataTypes.BOOLEAN,
    numberOfRoomsMin: DataTypes.REAL,
    numberOfRoomsMax: DataTypes.REAL,
    numberOfFloorsMin: DataTypes.INTEGER,
    numberOfFloorsMax: DataTypes.INTEGER,
    floorMin: DataTypes.INTEGER,
    floorMax: DataTypes.INTEGER,
    accessRoadType: DataTypes.TEXT,
    heatingType: DataTypes.TEXT
  });

  return SearchRequest;
};
