const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

/**
 * Service Model
 * Represents appointment services (flights, hotels, trains, etc.)
 */
const Service = sequelize.define('Service', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
  },
  categoryId: {
    type: DataTypes.UUID,
    allowNull: false,
    field: 'category_id',
    references: {
      model: 'category',
      key: 'id',
    },
  },
  serviceType: {
    type: DataTypes.STRING(50),
    allowNull: true,
    field: 'service_type',
    comment: '服务具体类型，用于跳转对应预约表单',
  },
  titleZh: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'title_zh',
  },
  titleEn: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'title_en',
  },
  titleEs: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'title_es',
  },
  descriptionZh: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'description_zh',
  },
  descriptionEn: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'description_en',
  },
  descriptionEs: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'description_es',
  },
  image: {
    type: DataTypes.STRING(500),
    allowNull: true,
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: true,
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    defaultValue: 'active',
    allowNull: false,
  },
  sortOrder: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    allowNull: false,
    field: 'sort_order',
  },
}, {
  tableName: 'service',
  timestamps: true,
  underscored: true,
  indexes: [
    { fields: ['category_id'] },
    { fields: ['status'] },
    { fields: ['sort_order'] },
  ],
});

module.exports = Service;
