module.exports = (sequelize, DataTypes) => {
  const DimensionalPressBrakeReport = sequelize.define('DimensionalPressBrakeReport', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    company_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    plant_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    fiscal_year_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    report_no: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true
    },
    report_date: {
      type: DataTypes.DATEONLY,
      allowNull: false
    },
    report_type: {
      type: DataTypes.STRING(30),
      allowNull: false,
      defaultValue: 'PRESS_BRAKE'
    },
    work_order_id: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    part_name: {
      type: DataTypes.STRING(200),
      allowNull: false
    },
    item_code: {
      type: DataTypes.STRING(100),
      allowNull: true
    },
    drawing_no: {
      type: DataTypes.STRING(100),
      allowNull: true
    },
    order_no: {
      type: DataTypes.STRING(100),
      allowNull: true
    },
    order_qty: {
      type: DataTypes.DECIMAL(18, 3),
      allowNull: true
    },
    customer_id: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    customer_name: {
      type: DataTypes.STRING(200),
      allowNull: true
    },
    revision_no: {
      type: DataTypes.STRING(50),
      allowNull: true
    },
    machine_id: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    machine_name: {
      type: DataTypes.STRING(100),
      allowNull: true
    },
    quantity: {
      type: DataTypes.DECIMAL(18, 3),
      allowNull: true
    },
    operator_name: {
      type: DataTypes.STRING(100),
      allowNull: true
    },
    remarks: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    inspected_by: {
      type: DataTypes.STRING(100),
      allowNull: true
    },
    inspected_by_user_id: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    inspection_date: {
      type: DataTypes.DATEONLY,
      allowNull: true
    },
    status: {
      type: DataTypes.ENUM('DRAFT', 'SUBMITTED', 'APPROVED', 'CANCELLED'),
      allowNull: false,
      defaultValue: 'DRAFT'
    },
    created_by: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    updated_by: {
      type: DataTypes.INTEGER,
      allowNull: true
    }
  }, {
    tableName: 'dimensional_press_brake_report',
    underscored: true,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  });

  DimensionalPressBrakeReport.associate = function(models) {
    DimensionalPressBrakeReport.belongsTo(models.Company, { foreignKey: 'company_id', as: 'company' });
    DimensionalPressBrakeReport.belongsTo(models.Plant, { foreignKey: 'plant_id', as: 'plant' });
    DimensionalPressBrakeReport.belongsTo(models.FiscalYear, { foreignKey: 'fiscal_year_id', as: 'fiscalYear' });
    DimensionalPressBrakeReport.belongsTo(models.BusinessPartner, { foreignKey: 'customer_id', as: 'customer' });
    DimensionalPressBrakeReport.belongsTo(models.Machine, { foreignKey: 'machine_id', as: 'machine' });
    DimensionalPressBrakeReport.belongsTo(models.User, { foreignKey: 'inspected_by_user_id', as: 'inspector' });
    DimensionalPressBrakeReport.belongsTo(models.User, { foreignKey: 'created_by', as: 'creator' });
    DimensionalPressBrakeReport.belongsTo(models.User, { foreignKey: 'updated_by', as: 'updater' });
    DimensionalPressBrakeReport.hasMany(models.DimensionalPressBrakeReportDetail, { foreignKey: 'report_id', as: 'details' });
  };

  return DimensionalPressBrakeReport;
};

