import { DataTypes } from 'sequelize';

// This will be used for dynamic database connections
export const createSurveyModel = (sequelize) => {
  return sequelize.define('Survey', {
    survey_id: { 
      type: DataTypes.INTEGER, 
      primaryKey: true, 
      autoIncrement: true 
    },
    tree_name: { 
      type: DataTypes.STRING(200), 
      allowNull: false 
    },
    local_name: { 
      type: DataTypes.STRING(200), 
      allowNull: true 
    },
    other_name: { 
      type: DataTypes.STRING(200), 
      allowNull: true 
    },
    latitude: { 
      type: DataTypes.DECIMAL(10, 8), 
      allowNull: false 
    },
    longitude: { 
      type: DataTypes.DECIMAL(11, 8), 
      allowNull: false 
    },
    tree_height: { 
      type: DataTypes.DECIMAL(8, 2), 
      allowNull: true 
    },
    tree_girth: { 
      type: DataTypes.DECIMAL(8, 2), 
      allowNull: true 
    },
    tree_age: { 
      type: DataTypes.INTEGER, 
      allowNull: true 
    },
    tree_condition: { 
      type: DataTypes.STRING(50), 
      allowNull: true 
    },
    tree_ownership: { 
      type: DataTypes.STRING(50), 
      allowNull: true 
    },
    economic_importance: { 
      type: DataTypes.STRING(50), 
      allowNull: true 
    },
    remarks: { 
      type: DataTypes.TEXT, 
      allowNull: true 
    },
    species_type: { 
      type: DataTypes.STRING(50), 
      allowNull: true 
    },
    is_heritage: { 
      type: DataTypes.BOOLEAN, 
      allowNull: false, 
      defaultValue: false 
    },
    is_rare: { 
      type: DataTypes.BOOLEAN, 
      allowNull: false, 
      defaultValue: false 
    },
    is_indigenous: { 
      type: DataTypes.BOOLEAN, 
      allowNull: false, 
      defaultValue: true 
    },
    is_exotic: { 
      type: DataTypes.BOOLEAN, 
      allowNull: false, 
      defaultValue: false 
    },
    host_plants: { 
      type: DataTypes.TEXT, 
      allowNull: true 
    },
    images: { 
      type: DataTypes.JSON, 
      allowNull: true 
    },
    user_id: { 
      type: DataTypes.INTEGER, 
      allowNull: false 
    },
    client_id: { 
      type: DataTypes.INTEGER, 
      allowNull: false 
    },
    treelogy_id: { 
      type: DataTypes.INTEGER, 
      allowNull: false 
    },
    survey_date: { 
      type: DataTypes.DATE, 
      allowNull: false, 
      defaultValue: DataTypes.NOW 
    },
    entered_time: { 
      type: DataTypes.DATE, 
      allowNull: false, 
      defaultValue: DataTypes.NOW 
    },
    status: { 
      type: DataTypes.STRING(20), 
      allowNull: false, 
      defaultValue: 'ACTIVE' 
    },
    verified: { 
      type: DataTypes.BOOLEAN, 
      allowNull: false, 
      defaultValue: false 
    },
    verified_by: { 
      type: DataTypes.INTEGER, 
      allowNull: true 
    },
    verified_at: { 
      type: DataTypes.DATE, 
      allowNull: true 
    }
  }, {
    tableName: 'surveys',
    schema: 'public',
    timestamps: false
  });
};

export default createSurveyModel;
