module.exports = (sequelize, DataTypes) => {
  const PrintHeader = sequelize.define('PrintHeader', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    company_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'Company',
        key: 'id'
      },
      comment: 'Company this print header belongs to'
    },
    header_code: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true,
      comment: 'Unique code for the print header'
    },
    header_name: {
      type: DataTypes.STRING(200),
      allowNull: false,
      comment: 'Name/description of the print header'
    },
    logo_path: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: 'Path to company logo file'
    },
    logo_file_name: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: 'Original filename of the logo'
    },
    company_name: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: 'Company name to display on print header'
    },
    former_name: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: 'Former name of the company (e.g., Formerly Known as...)'
    },
    address: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: 'Complete address for print header'
    },
    phone: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: 'Phone number(s)'
    },
    fax: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: 'Fax number'
    },
    email: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: 'Email address'
    },
    website: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: 'Website URL'
    },
    gstin: {
      type: DataTypes.STRING(15),
      allowNull: true,
      comment: 'GSTIN (GST Identification Number)'
    },
    quality_certification_logo_path: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: 'Path to quality certification logo file'
    },
    quality_certification_logo_file_name: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: 'Original filename of the certification logo'
    },
    quality_certification_text: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: 'Quality certification text (e.g., ISO 9001, DNV)'
    },
    quality_certification_body: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: 'Certification body (e.g., DNV)'
    },
    status: {
      type: DataTypes.ENUM('ACTIVE', 'INACTIVE'),
      allowNull: false,
      defaultValue: 'ACTIVE'
    },
    created_by: {
      type: DataTypes.INTEGER,
      allowNull: true,
      references: {
        model: 'User',
        key: 'id'
      }
    },
    updated_by: {
      type: DataTypes.INTEGER,
      allowNull: true,
      references: {
        model: 'User',
        key: 'id'
      }
    }
  }, {
    tableName: 'print_header',
    indexes: [
      {
        unique: true,
        fields: ['header_code']
      },
      {
        fields: ['company_id']
      },
      {
        fields: ['status']
      }
    ]
  });

  PrintHeader.associate = function(models) {
    PrintHeader.belongsTo(models.Company, { foreignKey: 'company_id', as: 'company' });
    PrintHeader.belongsTo(models.User, { foreignKey: 'created_by', as: 'creator' });
    PrintHeader.belongsTo(models.User, { foreignKey: 'updated_by', as: 'updater' });
  };

  return PrintHeader;
};

