import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';

class DayProduction extends Model { }

DayProduction.init({
    regionId: {
        type: DataTypes.INTEGER,
        allowNull: false},
    productId: {
        type: DataTypes.INTEGER,
        allowNull: false},
    quantity: {
        type: DataTypes.INTEGER,
        allowNull: false},
    producerId: {
        type: DataTypes.INTEGER,
        allowNull: false},
    productionTimestamp: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: sequelize.literal('CURRENT_TIMESTAMP')},
    productionDate: {
        type: DataTypes.DATEONLY,
        allowNull: false,
        defaultValue: sequelize.literal('CURRENT_DATE')}
}, {
    sequelize,
    modelName: 'DayProduction',
    tableName: 'production',
    schema: 'falukant_log',
    timestamps: false,
    underscored: true,
    indexes: [
        {
            unique: true,
            fields: ['producer_id', 'product_id', 'region_id', 'production_date']
        }
    ]
});

export default DayProduction;
