"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    const tableFields = {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
        primaryKey: true
      },
      areaToSearch: {
        type: Sequelize.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: Sequelize.TEXT,
        allowNull: false
      },
      adType: {
        type: Sequelize.TEXT,
        allowNull: false,
        defaultValue: "sell"
      },
      email: Sequelize.TEXT,
      locality: Sequelize.TEXT,
      municipality: Sequelize.TEXT,
      city: Sequelize.TEXT,
      region: Sequelize.TEXT,
      entity: Sequelize.TEXT,
      country: Sequelize.TEXT,
      sizeMin: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0
      },
      sizeMax: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0
      },
      priceMin: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0
      },
      priceMax: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0
      },
      gardenSizeMin: Sequelize.INTEGER,
      gardenSizeMax: Sequelize.INTEGER,
      subscribed: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false
      },
      createdAt: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("NOW()")
      },
      updatedAt: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("NOW()")
      }
    };
    return queryInterface.createTable("SearchRequests", tableFields);
  },

  down: queryInterface => {
    return queryInterface.dropTable("SearchRequests", {});
  }
};
