const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const ProjectManagements = sequelize.define(
    "projectmanagement",
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      creation: { type: DataTypes.DATE, allowNull: false },
      modified: { type: DataTypes.DATE, allowNull: false },
      modified_by: { type: DataTypes.INTEGER, allowNull: false },
      owner: { type: DataTypes.INTEGER, allowNull: false },
      enabled: { type: DataTypes.BOOLEAN, allowNull: false },

      pic: { type: DataTypes.STRING(100), allowNull: false },
      project_name: { type: DataTypes.STRING, allowNull: false },
      project_status: { type: DataTypes.INTEGER, allowNull: false },
      marketing_team: { type: DataTypes.STRING(100), allowNull: true },
      development_category: { type: DataTypes.STRING(100), allowNull: true },
      collaboration_type: { type: DataTypes.STRING(100), allowNull: true },
      import_local: { type: DataTypes.STRING(100), allowNull: true },
      country_origin: { type: DataTypes.STRING(100), allowNull: true },
      shipping_method: { type: DataTypes.STRING(100), allowNull: true },
      principal: { type: DataTypes.STRING(100), allowNull: true },
      top: { type: DataTypes.STRING(100), allowNull: true },
      website: { type: DataTypes.STRING(100), allowNull: true },
      pic_manufacturer: { type: DataTypes.STRING(100), allowNull: true },
      pic_manufacturer_email: { type: DataTypes.STRING(100), allowNull: true },

      factory_assesment: { type: DataTypes.DATE, allowNull: true },
      start_development: { type: DataTypes.DATE, allowNull: true },
      reg_category: { type: DataTypes.STRING, allowNull: true },
      mh_holder: { type: DataTypes.STRING, allowNull: true },

      formulation: { type: DataTypes.STRING, allowNull: true },
      shape: { type: DataTypes.STRING, allowNull: true },
      usp: { type: DataTypes.TEXT, allowNull: true },
      marketing_plan: { type: DataTypes.DATE, allowNull: true },
      batch_size: { type: DataTypes.STRING, allowNull: true },
      moq: { type: DataTypes.STRING, allowNull: true },
      primary_pack: { type: DataTypes.STRING, allowNull: true },
      variation_pack: { type: DataTypes.STRING, allowNull: true },
      brand_name: { type: DataTypes.STRING, allowNull: true },
      design: { type: DataTypes.STRING, allowNull: true },
      quotation: { type: DataTypes.STRING, allowNull: true },
      cogs: { type: DataTypes.STRING, allowNull: true },
      proposed_hna: { type: DataTypes.STRING, allowNull: true },
      shelf_life: { type: DataTypes.STRING, allowNull: true },
      leadtime: { type: DataTypes.STRING, allowNull: true },
      open_po: { type: DataTypes.DATE, allowNull: true },
      batch1_production: { type: DataTypes.DATE, allowNull: true },
      batch1_ready: { type: DataTypes.DATE, allowNull: true },

      nda: { type: DataTypes.JSON, allowNull: true },
      da: { type: DataTypes.JSON, allowNull: true },
      pks_bpom: { type: DataTypes.JSON, allowNull: true },
      transfer_price: { type: DataTypes.JSON, allowNull: true },
      pilotscale_production: { type: DataTypes.JSON, allowNull: true },
      stab_test: { type: DataTypes.JSON, allowNull: true },
      hki: { type: DataTypes.JSON, allowNull: true },
      bpom_kemenkes: { type: DataTypes.JSON, allowNull: true },
      halal: { type: DataTypes.JSON, allowNull: true },
      variation: { type: DataTypes.JSON, allowNull: true },
      tkdn: { type: DataTypes.JSON, allowNull: true },
      internal_coordination: { type: DataTypes.JSON, allowNull: true },

      nda_document: { type: DataTypes.TEXT, allowNull: true },
      da_document: { type: DataTypes.TEXT, allowNull: true },
      pks_document: { type: DataTypes.TEXT, allowNull: true },

      //   fk
      company_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "companies",
          key: "id",
        },
      },
    },
    {
      tableName: "projectmanagements",
      freezeTableName: true,
    }
  );

  /**
   * Associates the Province model with other models.
   * @param {object} models - The models to associate with.
   */
  ProjectManagements.associate = (models) => {
    /**
     * Associates the DeliveryTrips model with the Company model.
     * A DeliveryTrip belongs to a Company.
     * @param {object} models - The models to associate with.
     */
    ProjectManagements.belongsTo(models.Company, {
      foreignKey: "company_id",
      as: "company",
    });
  };

  return ProjectManagements;
};
