"use strict";

module.exports = (sequalize, DataTypes) => {
  const KiviOriginalAdsPhotos = sequalize.define(
    "KiviOriginalAdsPhotos",
    {
      id: {
        type: DataTypes.BIGINT,
        autoIncrement: true,
        primaryKey: true,
        allowNull: false
      },
      kiviAdId: {
        type: DataTypes.UUID,
        allowNull: false,
        references: {
          model: "KiviOriginal",
          key: "kiviAdId"
        }
      },
      photoUrl: {
        type: DataTypes.TEXT,
        allowNull: false
      }
    },
    {
      freezeTableName: true
    }
  );

  KiviOriginalAdsPhotos.associate = models => {
    KiviOriginalAdsPhotos.hasMany(models.KiviOriginal, {
      foreignKey: "kiviAdId",
      sourceKey: "kiviAdId",
      targetKey: "kiviAdId",
      as: "kiviOriginal"
    });
  };

  return KiviOriginalAdsPhotos;
};
