'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('booking_rules', {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        primaryKey: true,
      },
      service_type: {
        type: Sequelize.STRING(50),
        allowNull: false,
        unique: true,
        comment: '服务类型标识',
      },
      rules: {
        type: Sequelize.TEXT,
        allowNull: true,
        comment: '预约登记规则内容',
      },
      status: {
        type: Sequelize.ENUM('active', 'inactive'),
        defaultValue: 'active',
        allowNull: false,
        comment: '状态',
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
      },
    });

    // 添加索引
    await queryInterface.addIndex('booking_rules', ['service_type'], {
      unique: true,
      name: 'booking_rules_service_type_unique'
    });
    await queryInterface.addIndex('booking_rules', ['status'], {
      name: 'booking_rules_status'
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('booking_rules');
  }
};
