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

class ActivityLog extends Model {
    static associate(models) {
        // User 모델과의 연관 관계 설정
        ActivityLog.belongsTo(models.User, {
            foreignKey: 'userId',
            as: 'User'
        });
    }
}

ActivityLog.init({
    id: {
        type: DataTypes.INTEGER.UNSIGNED,
        primaryKey: true,
        autoIncrement: true,
        comment: '활동 로그 고유 식별자'
    },
    userId: {
        type: DataTypes.INTEGER.UNSIGNED,
        allowNull: false,
        references: {
            model: 'Users',
            key: 'id'
        },
        comment: '유저 ID'
    },
    type: {
        type: DataTypes.STRING(50),
        allowNull: false,
        comment: '로그 유형'
    },
    description: {
        type: DataTypes.TEXT,
        allowNull: true,
        comment: '상세 설명'
    },
    createdAt: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
        comment: '생성일'
    }
}, {
    sequelize,
    comment: '유저 활동 로그를 저장하는 테이블',
    modelName: 'ActivityLog',
    tableName: 'ActivityLogs',
    timestamps: true,
    updatedAt: false
});

module.exports = ActivityLog;
